Follow up: I have tested it with OpenJPA 2.3.0 and the error is still 
happening. :-( Meanwhile, I’ve put back the dependency to EclipseLink and the 
problem doesn’t happen in this case. That’s a pity because the environment I’m 
using (TomEE) has OpenJPA as the JPA implementation. It’s always good to 
optimise dependencies. The entity class is the following:

https://github.com/htmfilho/architect/blob/master/src/main/java/com/hildeberto/architect/system/domain/Functionality.java

The method save(Functionality functionality) is trying to persist this class:

https://github.com/htmfilho/architect/blob/master/src/main/java/com/hildeberto/architect/system/business/FunctionalityBean.java

On 27 Nov 2013, at 13:49, Hildeberto Mendonça Filho <hildebe...@yougi.org> 
wrote:

> Hello,
> 
> I'm currently migrating from EclipseLink to OpenJPA 2.2.0 to access MySQL 5. 
> Since I use AUTO_INCREMENT in my entity classes, I have my id field annotated 
> with:
> 
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> 
> When I try to persist a new entity I get the following exception:
> 
> javax.servlet.ServletException: javax.el.ELException: javax.ejb.EJBException: 
> The bean encountered a non-application exception; nested exception is:
> <openjpa-2.2.0-r422266:1244990 fatal store error> 
> org.apache.openjpa.persistence.OptimisticLockException: Attempted to attach 
> deleted instance type "class 
> com.hildeberto.architect.system.domain.Functionality" with oid "0".  If the 
> instance is new, the version field should be left to its default value.
> FailedObject: com.hildeberto.architect.system.domain.Functionality@3ca76aa1
>       javax.faces.webapp.FacesServlet.service(FacesServlet.java:229)
> 
> *cause mère*
> 
> org.apache.myfaces.view.facelets.el.ContextAwareELException: 
> javax.el.ELException: javax.ejb.EJBException: The bean encountered a 
> non-application exception; nested exception is:
>       <openjpa-2.2.0-r422266:1244990 fatal store error> 
> org.apache.openjpa.persistence.OptimisticLockException: Attempted to attach 
> deleted instance type "class 
> com.hildeberto.architect.system.domain.Functionality" with oid "0".  If the 
> instance is new, the version field should be left to its default value.
> FailedObject: com.hildeberto.architect.system.domain.Functionality@3ca76aa1
>       
> org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:108)
>       
> org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:68)
>       javax.faces.component.UICommand.broadcast(UICommand.java:120)
>       javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
>       javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
>       javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
>       javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
>       
> org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
>       
> org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
>       
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
>       javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
> 
> When I remove the annotation @GeneratedValue it works. It doesn't make sense 
> to me because this annotation is part of the specification. My 
> persistence.xml is configured as follows:
> 
> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
> http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";>
>  <persistence-unit name="architect-pu" transaction-type="JTA">
>    <jta-data-source>jdbc/architect</jta-data-source>
> <exclude-unlisted-classes>false</exclude-unlisted-classes>
>    <properties>
>        <property name="openjpa.Log" value="SQL=TRACE"/>
>        <property name="openjpa.ConnectionFactoryProperties" 
> value="PrettyPrint=true, PrettyPrintLineLength=72"/>
>        <property name="openjpa.jdbc.DBDictionary" 
> value="org.apache.openjpa.jdbc.sql.MySQLDictionary"/>
>    </properties>
>  </persistence-unit>
> </persistence>
> 
> I made some research but didn't get any conclusive solution for that.
> 
> Thanks in advance for any advice.
> 
> Hildeberto

Reply via email to