Massimo Ugues
Massimo Ugues

Reputation: 4463

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?

Upvotes: 0

Views: 2076

Answers (1)

James
James

Reputation: 18379

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.

Upvotes: 2

Related Questions