Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code> Hibernate merge was not meant for associating transient objects to persistent ones. </code></pre> <p>The merge() should ideally work for you because you are actually dealing with detached object. Since you are setting ids in the 'transObj' before calling merge, hibernate would consider them as detached (not transient).</p> <p>I think the problem with your code is that it is tripping hibernate. </p> <p>In your code, you are loading the 'persistObj' from the database. Now, hibernate holds this 'persistObj' in session. You are then setting some of the ids from 'persistObj' in 'transObj' and then calling merge. Some of the child objects in 'persistObj' and 'transObj' have the same ids, hibernate gets confused. </p> <pre><code>ComplexObject transObj = xstream.import("object.xml"); ComplexObject persistObj = someService.getObjByName(transObj.getName()); for (OtherObject o : c.getObjects()) { if (persistObj.getObjects().contains(o.getName())) { o.setId(persistObj.getObjectByName(o.getName()).getId()) } ... set a bunch of other IDs deeper in the object graph ... } transObj = session.merge(transObj); session.saveOrUpdate(transObj); </code></pre> <p>Try calling the the session.clear() after loading 'persistObj', so that hibernate removes the persistObj and considers only your detached object. </p> <pre><code>ComplexObject transObj = xstream.import("object.xml"); ComplexObject persistObj = someService.getObjByName(transObj.getName()); // Clear the session, so that hibernate removes 'persistObj' from it's cache session.clear(); for (OtherObject o : c.getObjects()) { if (persistObj.getObjects().contains(o.getName())) { o.setId(persistObj.getObjectByName(o.getName()).getId()) } ... set a bunch of other IDs deeper in the object graph ... } transObj = session.merge(transObj); session.saveOrUpdate(transObj); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload