[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] detached object changes aren't completely merged?


In your client side code, try using your setter methods instead of directly setting the instance variables.

EclipseLink is weaving the classes to track changes and the direct set of the instance variable is defeating the weaving. (We can only weave the code that handles the changes into your entity class, so direct variable sets outside of your entity class will not have changes tracked) I suspect that if you truly removed the object from the VM through a mechanism like serialization and then reconstituted it, you would not see the problem either.

Another way to avoid this problem is likely to set the persistence unit property eclipselink.weaving.changetracking to false.


On 30/11/2012 7:07 AM, hilmarf wrote:

I have some trouble with merging detached objects. I have a client server
scenario where I send collections of persisted objects to a client, so the
user is able to do changes on the objects in a simple gui.

When the user changes a name (simple string) and a relation to an other
persisted object, the name change isn't correctly merged!?!?

         // refresh the parent and
         // detach parent e.g. send over network to client

         // query a child
         child = em.createQuery("select c from Child c where c.name = 'son'",
         // detach it e.g. send over network to client
         // SERVER-SIDE-END

         // CLIENT-SIDE
         System.out.println("selected '" + child + "' for change");
         final String MISSING_CHANGED_STRING = "baby";
         child.name = MISSING_CHANGED_STRING;
         child.parent = mom;
         final String PARENT_NAME_STRING = child.parent.name;
         // CLIENT-SIDE-END

         // SERVER-SIDE
         em = emf.createEntityManager();
         // try to merge changes
         transaction = em.getTransaction();
         System.out.println(child + " changed");
         child = em.merge(child);
         System.out.println(child + " merged");

         // the parent is fine:
         assert child.parent.name.equals(PARENT_NAME_STRING);

         // expected behavior:
         assert child.name.equals(MISSING_CHANGED_STRING) : "expected name:
                 + "' and not '" + child.name + "'";

The complete sources are here in the attached zip file.
src.zip <http://eclipse.1072660.n5.nabble.com/file/n156056/src.zip>

Any HELP is appreciated!!!

View this message in context: http://eclipse.1072660.n5.nabble.com/detached-object-changes-aren-t-completely-merged-tp156056.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
eclipselink-users mailing list