开发者

JPA one-to-many join table with additional information

开发者 https://www.devze.com 2023-02-04 11:07 出处:网络
I have these ER relations: Person ID_PERSON NAME Animal ID_ANIMAL NAME Person_animal ID_PERSON ID_ANIMAL DATE_OF_BUY

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

精彩评论

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