开发者

Modelling a manyToMany relationship with attributes

开发者 https://www.devze.com 2023-01-01 09:51 出处:网络
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 ne

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.

0

精彩评论

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

关注公众号