I have a domain object that holds a collection of another object through a @ManyToMany annotaion:
@ManyToMany(fetch=FetchType.LAZY,cascade = { CascadeType.MERGE, CascadeType.PERSIST})
@JoinTable(name = "join_table", joinColumns=@JoinColumn(name="a_id", referencedColumnName = "a_id"), inverseJoinColumns=@JoinColumn(name = "b_id", referencedColumnName = "b_id"))
private List<B> BsList;
In the join table i hold additional data columns.
I noticed that when i work with the object that holds the list and call setBsList() the data i had in the additional columns is deleted.
Does Hibernate re-write the rows in the join table each time?
If you have additional data columns, it’s not a join table. It’s a table with two FKs which can also be PKs. And Hibernate is doing the right thing. So, you should instead create another entity representing this “fake join table”, and map it accordingly.