Skip to main content

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

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.


Back to the top