tags:

views:

57

answers:

3

Hello,

I have a ManyToMany relationship between two classes, for instance class Customer and class Item. A customer can buy several items and an item can be bought by different customers. I need to store extra information in this relationship, for example the day when the item was bought. I wonder how is this usually modelled in JPA, cause I'm not sure how to express this in code. Do I have to create a new class to model all the attributes of the relationship and make a manyToMany relationship between the other classes or is a better way to do this?

Thanks

+1  A: 

The recommended way is to create a new association class to store the needed attributes, and two one-to-many associations to the two parties involved.

Péter Török
+1  A: 

I guess you will indeed have to create a new class for the relationship.

Maurice Perry
+1  A: 

Like you said yourself, the correct way is to create a new class with the additional attributes.

Kim L