users@glassfish.java.net

Re: GF V3 Embedded Container: Problem with JPA, Entity is not managed

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 10 Feb 2010 13:33:17 -0800

Your client gets a detached version of the entity from the holidayEJB.find(id),
so holidayEJB.remove() should first merge it, then remove the attached version.
Look at e.g.
https://glassfish.dev.java.net/javaee5/persistence/persistence-example.html

Regards,
-marina

glassfish_at_javadesktop.org wrote:
> Hello,
>
> I'm trying to run Junittests from Eclipse-IDE on the GF embedded container. But the container behaves curious. The project is an ejb-project with an entity and an ejb to manage the entity. When starting the container, all works fine. The jndi-names are created properly and the database is opened. The entity is persisted to DB with the persist-method - works fine. But when I try to call remove on the eib, the container is saying:
> java.lang.IllegalArgumentException: Entity must be managed to call remove: model.PublicHoliday_at_616364, try merging the detached and try the remove again.
>
> I'm very puzzled.
>
> Here is the Testmethod:
> @Test
> public void createHoliday() throws Exception {
> PublicHoliday holiday = new PublicHoliday();
> PublicHolidayEJB holidayEJB = (PublicHolidayEJB) ctx.lookup("java:global/classes/PublicHolidayEJB");
>
> // save holiday
> holiday.setName("test");
> holidayEJB.persist(holiday);
> long id = holiday.getId();
> assertTrue("id is generated", id > 0);
>
> // search holiday
> holiday = holidayEJB.find(id);
> assertNotNull("entity loaded", holiday);
>
> // At this point, the tx is commited and the entity is in DB
> holidayEJB.remove(holiday); //java.lang.IllegalArgumentException:
> //Entity must be managed to call remove:
> //model.PublicHoliday_at_616364,
> //try merging the detached and try the remove again.
> System.out.println("finished");
> }
>
> And here is the persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
> <persistence-unit name="holidayTestPU" transaction-type="JTA">
> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
> <jta-data-source>jdbc/timeGetterDS</jta-data-source>
> <class>model.PublicHoliday</class>
> <properties>
> <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
> <property name="eclipselink.logging.level" value="FINE"/>
> </properties>
> </persistence-unit>
> </persistence>
>
> I'm thankful for every tip...
> Peter
> [Message sent by forum member 'pepatpx' (prope_at_t-online.de)]
>
> http://forums.java.net/jive/thread.jspa?messageID=385835
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>