开发者

JPA one-to-many join table with additional information

I have these ER relations:

Person

ID_PERSON

NAME

Animal

ID_ANIMAL

NAME

Person_animal

ID_PERSON

ID_ANIMAL

DATE_OF_BUY

How 开发者_如何转开发to map the property DATE_OF_BUY in the association?


The best way is normally to map the join table to a relationship class. i.e.

Person - OneToMany - AnimalOwnership - ManyToOne - Animal

See,

http://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Mapping_a_Join_Table_with_Additional_Columns

In JPA 2.0 you can also use a MapKey for some additional data, but this is normally more complex.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜