Skip to main content

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

Hi,

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.

-Tom

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

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
         em.refresh(mom);
         // detach parent e.g. send over network to client
         em.detach(mom);

         // query a child
         child = em.createQuery("select c from Child c where c.name = 'son'",
Child.class).getSingleResult();
         // detach it e.g. send over network to client
         em.detach(child);
         em.close();
         // 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();
         transaction.begin();
         System.out.println(child + " changed");
         child = em.merge(child);
         System.out.println(child + " merged");
         transaction.commit();
         em.close();
         emf.close();

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

         // expected behavior:
         assert child.name.equals(MISSING_CHANGED_STRING) : "expected name:
'" + MISSING_CHANGED_STRING
                 + "' 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
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top