users@glassfish.java.net

Re: em.merge after em.persist problem

From: <glassfish_at_javadesktop.org>
Date: Tue, 10 Nov 2009 01:19:58 PST

Entitymanager attaches the Entity to the persistence context when you're doing persist().
As the Stock Entity you are edit()ing isn't attached, the Entitymanager is treating it as a new Entity and creates it.

What you need to do is return the attached Entity in create():

public Stock create(Stock stock) {
em.persist(stock);
return Stock
}

and use this with setName() and edit().

For examples on CRUD operations, see http://weblogs.java.net/blog/2009/04/19/generic-crud-facade-your-entity-beans

-Matthias
[Message sent by forum member 'matthiasfraass' (matthias.fraass_at_tricoder.net)]

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