开发者

Composition mapping in Hibernate using annotation?

开发者 https://www.devze.com 2023-02-12 11:31 出处:网络
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 bet

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号