Hibernate one to many relationship with join table with addition columns in join table

混江龙づ霸主 提交于 2019-12-06 01:56:51

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.

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

And CategorizedAddress would have a property of type Address, and a property containing the category.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!