Composition mapping in Hibernate using annotation?
how can I define a data model (including 2 classes A and B, B is contained in A) that satisfy the B's id is the same with A's id (because I want to make 开发者_开发百科an one-to-one relationship between A and B), using composition mapping by Hibernate annotations? Could you please give a a code example to refer? Thank you very much.
It is called shared primary key one-to-one associations . I found an bi-directional example here http://www.codereye.com/2009/04/hibernate-bi-directional-one-to-one.html .
@GenericGenerator adds a foreign key constraint linking the PK of the person_details table to the PK of the person table to guarantees that a person_details row’s primary key always references a valid person table 's primary key , so their relationship is one-to-one.
精彩评论