I have a many to may relationship CohortGroup and Employee. Any time I insert an Employee into the CohortGroup hibernate deletes the group from the resolution table and ins
Load the object in persistence context and call merge if exist and save if not exist.
Employee emp = new Employee();
//set emp attribute and members.
Session session = ...
Transaction transaction = ...
Employee db = (Employee) session.get(Employee .class,emp.getId());
if(db != null) session.merge(emp);
else session.save(emp);
/*session.saveOrUpdate(emp); This will delete the join table and reinsert entry
again*/
transaction.commit();
session.close();