Modelling a manyToMany relationship with attributes
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
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.
I guess you will indeed have to create a new class for the relationship.
Like you said yourself, the correct way is to create a new class with the additional attributes.
精彩评论