我正在寻找在两个表之间具有@OneToMany关系并在联接表中具有额外属性的方法,但我找不到周围有用的示例.抱歉,这听起来很la脚,但有什么可以建议我这样做的好方法.
I am looking for a way to have a @OneToMany relation between two tables and having extra attributes in the join table and I am not able to find much useful examples around. Sorry if this sounds lame but can any suggest me a good way for it.
推荐答案如果联接表中还有其他列,则它不再是联接表,您需要一种方法来获取和设置这些列中的值.因此答案很简单:该表需要映射为一个实体.
If you have additional columns in the join table, it's not a join table anymore, and you need a way to get and set values in these columns. So the answer is simple: the table needs to be mapped as an entity.
例如,假设您有一个Person实体和一个Address实体.这个人有几个地址.现在,我们假设必须对每个地址进行分类:家庭住址,专业地址等.要映射地址的类别,您需要一个实体:
For example, let's say you have a Person entity and an Address entity. And the person has several addresses. Now let's say each address must be categorized: home address, professional address, etc. To be able to map the category of the address, you need an entity:
Person 1 ---> N CategorizedAddress 1 ---> 1 Address和CategorizedAddress将具有地址类型的属性,以及包含类别的属性.
And CategorizedAddress would have a property of type Address, and a property containing the category.
更多推荐
休眠与联接表的一对多关系,并在联接表中添加列
发布评论