geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: EntityExistsException: Attempt to persist detached object
Date Mon, 26 Nov 2007 17:31:58 GMT
My experience is that to get openjpa sequences to work you NEED a non  
transactional non-jta-datasource specified in your persistence.xml

		<non-jta-data-source>yyyDataSouurce</non-jta-data-source>

where the configuration of yyyDataSouurce includes

<no-transaction/>

In particular it can't be the same datasource you use for the jta- 
data-source

thanks
david jencks


On Nov 22, 2007, at 6:12 AM, maho77 wrote:

>
> Hello, I get the following Exception, when I try to persist an Entity:
>
> 14:53:06,841 ERROR [LoginAdminImpl] Fehler beim Speichern der MTIGroup
> <openjpa-1.0.0-r420667:568756 nonfatal store error>
> org.apache.openjpa.persistence.EntityExistsException: Attempt to  
> persist
> detached object "entities.MTIGroup@61a661a6".
> FailedObject: entities.MTIGroup@61a661a6
> 	at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2358)
> 	at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2216)
> 	at
> org.apache.openjpa.kernel.DelegatingBroker.persist 
> (DelegatingBroker.java:1005)
> 	at
> org.apache.openjpa.persistence.EntityManagerImpl.persist 
> (EntityManagerImpl.java:541)
> 	at
> org.apache.geronimo.persistence.CMPEntityManagerTxScoped.persist 
> (CMPEntityManagerTxScoped.java:83)
> 	at beans.LoginAdminImpl.createGroup(LoginAdminImpl.java:159)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:79)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:618)
> 	at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext 
> $Invocation.invoke(ReflectionInvocationContext.java:146)
> 	at
> org.apache.openejb.core.interceptor.ReflectionInvocationContext.procee 
> d(ReflectionInvocationContext.java:129)
> 	at
> org.apache.openejb.core.interceptor.InterceptorStack.invoke 
> (InterceptorStack.java:67)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer._invoke 
> (StatelessContainer.java:203)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer.invoke 
> (StatelessContainer.java:165)
> 	at
> org.apache.openejb.server.ejbd.EjbRequestHandler.doEjbObject_BUSINESS_ 
> METHOD(EjbRequestHandler.java:212)
> 	at
> org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest 
> (EjbRequestHandler.java:120)
> 	at
> org.apache.openejb.server.ejbd.EjbDaemon.processEjbRequest 
> (EjbDaemon.java:164)
> 	at org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java: 
> 122)
> 	at org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java: 
> 84)
> 	at org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java: 
> 60)
> 	at org.apache.openejb.server.ServiceLogger.service 
> (ServiceLogger.java:73)
> 	at
> org.apache.openejb.server.ServiceAccessController.service 
> (ServiceAccessController.java:55)
> 	at org.apache.openejb.server.ServiceDaemon$1.run 
> (ServiceDaemon.java:117)
> 	at java.lang.Thread.run(Thread.java:810)
>
> This is the Entity:
>
> @Entity
> @Table(name="group_table")
> public class MTIGroup implements Serializable, IMTIGroup {
>
> 	private int id = -1;
> 	private String name = new String();
> 	private String description = new String();
>
> 	public MTIGroup() {
> 	}
>
> 	@TableGenerator(name="GroupIdGen", table="ID_GENERATOR",
> pkColumnName="name", valueColumnName="id_value",
> 			pkColumnValue="group_table", initialValue=0, allocationSize=1)
> 	@Id
> 	@GeneratedValue(strategy=GenerationType.TABLE,  
> generator="GroupIdGen")
> 	public int getId() {
> 		return id;
> 	}
>
> 	public void setId(int id) {
> 		this.id = id;
> 	}
>
> 	public String getName() {
> 		return name;
> 	}
>
> 	public void setName(String name) {
> 		this.name = name;
> 	}
>
> 	public String getDescription() {
> 		return description;
> 	}
>
> 	public void setDescription(String description) {
> 		this.description = description;
> 	}
>
> }
>
> This is the StatefulBean-Method:
>
> 	@PersistenceContext(unitName="xxx")
> 	private EntityManager em;
> ...
> 	public void createGroup(MTIGroup group) {
> 		if (group != null) {
> 			try {
> 				em.persist(group);
> 			}
> 			catch (Exception e) {
> 				logger.error("Error saving MTIGroup", e);
> 			}
> 		}
> 	}
>
> This is the stand-alone client code:
> 		InitialContext ic = null;
> 		Properties properties = new Properties();
> properties.put 
> (Context.INITIAL_CONTEXT_FACTORY,"org.apache.openejb.client.RemoteInit 
> ialContextFactory");
> 		properties.put(Context.PROVIDER_URL,"ejbd://localhost:4201");
>
> 		try {
> 			ic = new InitialContext(properties);
> 			TestImplRemote lar = (TestImplRemote)ic.lookup 
> ("TestImplEJBRemote");
> 			MTIGroup g1 = new MTIGroup();
> 			g1.setId(2);
> 			g1.setName("testGroup");
> 			g1.setDescription("Description for testGroup");
> 			lar.createGroup(g1);
> 		} catch (NamingException e) {
> 			e.printStackTrace();
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		}
>
> and this the persistence.xml part:
>
> 	<persistence-unit name="xxx" >
> 		<jta-data-source>xxxDataSouurce</jta-data-source>
> 		<class>entities.MTIGroup</class>
> 		<exclude-unlisted-classes>true</exclude-unlisted-classes>
> 		<properties>
> 			<property name="openjpa.jdbc.SynchronizeMappings" value="false" />
> 			<property name="openjpa.jdbc.DBDictionary"
> value="mysql(SupportsSubselect=true)" />
> 			<property name="openjpa.Log"  
> value="DefaultLevel=TRACE,SQL=TRACE" />
> 			<property name="openjpa.AutoDetach" value="close" />
>             <property name="openjpa.DetachState" value="all" />
>             <property name="openjpa.DataCache" value="false" />
>             <property name="openjpa.Optimistic" value="true" />
>             <property name="openjpa.Multithreaded" value="true" />
>             <property name="openjpa.TransactionMode"  
> value="managed" />
>             <property name="openjpa.NontransactionalRead"  
> value="true" />
>             <property name="openjpa.RestoreState" value="all" />
> 		</properties>
> 	</persistence-unit>
>
> What goes wrong here? Other Entities can be persisted easily with  
> the same
> structure. I've already tried a bean managed transaction, all with  
> the same
> result. Can anybody help me and bring to the right direction?
>
> Thank you,
> Mark
>
> -- 
> View this message in context: http://www.nabble.com/ 
> EntityExistsException%3A-Attempt-to-persist-detached-object- 
> tf4856534s134.html#a13897173
> Sent from the Apache Geronimo - Users mailing list archive at  
> Nabble.com.
>


Mime
View raw message