Essentially, I have some objects in this configuration (the real data model is a bit more complicated):
- A has many-to-many relationship with B. (B has
inverse="true" ) - B has a multi-valued relationship with C. (My
cascade set to "save-update" ) - C is the type of type / category table.
Also, I should probably mention that primary keys are generated by the database when stored.
With my data, I sometimes encounter problems when A has many different B-objects, and these B objects belong to the same C object.
When I call session.saveOrUpdate(myAObject) , I get a sleep error: "a different object with the same identifier value was already associated with the session: C" . I know that hibernation cannot insert / update / delete the same object twice in the same session, but is there any way to do this? It does not look like this would be a rarity.
During my research on this problem, I saw people suggest using session.merge() , but when I do this, any "conflicting" objects are inserted into the database as empty objects with all values ββequal to zero. Clearly, this is not what we want.
[Edit] Another thing that I forgot to mention is that (for reasons not dependent on architecture) each reading or writing must be done in a separate session.
java hibernate
John Apr 26 '13 at 23:35 2013-04-26 23:35
source share