I have some objects in the following configuration:
· A has the many-to-many relationship with B. (B has inverse="true")
· B has the many-to-one relationship with C. (I have cascade set to "save-update")
· C is the kind of type or category table.
Also primary keys are generated by the database on the save.
But with my data sometimes I run into problems such as A has the set of different B objects and now these B objects refer to the same C object.
When I try to call session.saveOrUpdate(myAObject) I get following hibernate error which says: "a different object with the same identifier value was already associated with the session: C". I can understand that hibernate cannot insert/update/delete the same object twice in the same session, and so looking for some workaround on this? I don’t think this is the uncommon situation.
One thing I want to mention here is that for architectural reasons beyond my control each read or write needs to be done in a separate session.
Does anybody has any solution on my issue?