users@glassfish.java.net

Detached Entities and merge

From: <glassfish_at_javadesktop.org>
Date: Tue, 08 Jan 2008 08:57:15 PST

The JPA specs are confusing with respect to updating detached entities. My detached entity graph are getting updated after calling EntityManger merge and flush.

Using GlassFish v2/TopLink bundled with NetBeans 6 all default settings. Have a Web client, Servlet, calling a stateless session bean accessing local entity beans. Typical project per NetBeans 6 setup.

Scenario:

1. Client, Servlet, creates a graph of entities,
2. Client calls stateless sessonbean entityManager.persist(entity)
3. Client continues to update detached entities - inserts and updates
4. Client calls stateless sessionbean entityManager.merge(entity) and flush()

Result:
The detached entities are not updated, only the inserts are applied.

In debug mode, noticed TopLink Unit of Work operation is not creating SQL update commands, just insert queries.

So, how does the "Entity entity = em.merge(detachedEntity);" really work?

What is the proper way to update entities and synchronize the database?

Note, stateless and stateful sessionbeans have the problem.

Thank you for this great forum and GlassFish of course!
[Message sent by forum member 'bluesturbo' (bluesturbo)]

http://forums.java.net/jive/thread.jspa?messageID=252755