Rahul Babbar wrote:Yes....i think the problem is coming because you are doing
user.setMydepts(new HashSet());
According to this code, if there was anything in the original set, it should be removed....and it should be replaced by this new Set...
So, hibernate is doing what it should, remove the original records, and then add the new records...
I have not tested it, but some code like below should work.
I agree with Rahul.
In general, we do not use user.setMydepts(new HashSet()) as this method is to be used by hibernate internally to populate the HashSet.
You are calling this statement after the HashSet is already been populated by Hibernate.