java - Hibernate Join Tables -


i have 2 tables:

person

id | name | email_id (foreign key of email.id) 

email

id | email_address 

i need pull data following entity unsure how join person.email_id email.id using annotations

@entity @table(name = "person") public class personentity {     @column(name = "id")     private string id;      @column(name = "name")     private string name;      // how do 1 one join here?     private string emailaddress; } 

how can use annotations emailaddress field maps email.email_address column?

your person entity should join email entity , not emailaddress property directly.

@entity @table(name = "person") public class personentity {     @column(name = "id")     private string id;      @column(name = "name")     private string name;      @onetoone(fetch = fetchtype.lazy, mappedby = "person", cascade = cascadetype.all)     private email email; } 

but strange have entity emails. ensure email unique ? in case person entity can have emailaddress @column(unique = true).

@entity @table(name = "person") public class personentity {     @column(name = "id")     private string id;      @column(name = "name")     private string name;      @column(unique = true)     private string emailaddress; } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -