java - Hibernate - Three Entities in One Table -


i have problem setting hibernate annotations in entity classes.

my question is: how can tell hibernate, should store address, name , customer information in 1 table. table should have following columns: id, given, surname, street, housenumber, zip, city, phone, comment. @ moment hibernate generates each entity single table in mysql database. therefore necessary define @id in each entity class (customer, name, address). want keep information in 1 table 1 @id customer.

how can solve problem?

below can find extract of customer, name , address entity classes:

@entity @table(name = "customer") @xmlrootelement public class customer {     @id     @generatedvalue     private int id;     @onetoone     private name name;     @onetoone     private address address;     private string phone;     private string comment;     public customer() { } }  @entity @xmlrootelement public class name {     private string given;     private string surname;     public name() { } }  @entity @xmlrootelement public class address {     private string street;     private string housenumber;     private string zip;     private string city;     public address() { } } 

only customer should annotated @entity. other classes not entities, small part of customer entity. should annotated @embeddable.

@entity @table(name = "customer") public class customer {     @id     @generatedvalue     private int id;     @embedded     private name name;     @embedded     private address address;     private string phone;     private string comment;     public customer() { } }  @entity public class name {     private string given;     private string surname;     public name() { } }  @embeddable public class address {     private string street;     private string housenumber;     private string zip;     private string city;     public address() { }; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -