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.
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.
来源:https://stackoverflow.com/questions/21319031/hibernate-one-to-many-relationship-with-join-table-with-addition-columns-in-join