openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo K. Shikida" <shik...@gmail.com>
Subject Re: PersistenceException while trying to save class with composite primary key (@EmbeddedId/@Embeddable)
Date Thu, 21 Nov 2013 21:19:22 GMT
running embedded tomee 1.6.0+ to generate the initial JPA db schema and
populate with initial data

data source is declared from a properties

    private static Properties getOracleDatasource() {
        final Properties p = new Properties();
        p.put("poc1", "new://Resource?type=DataSource");
        p.put("poc1.JdbcDriver", "oracle.jdbc.OracleDriver");
        p.put("poc1.JdbcUrl", "jdbc:oracle:thin:@localhost:1521:XE");
        p.put("poc1.UserName", "xxx");
        p.put("poc1.Password", "xxx");
        return p;
    }

container is instantiated and EJBs are retrieved via JDNI lookup

ejbContainer = EJBContainer.createEJBContainer(p);
context = ejbContainer.getContext();
authEJB = (AuthEJB)
context.lookup("java:global/xyz/"+AuthEJB.class.getSimpleName());

EJBs provide transactional context and perform simple CRUD operations via
DAO classes

for example

        UserGroupAccess userGroupAccessAdmin = new UserGroupAccess();
        userGroupAccessAdmin.setActive(true);
        userGroupAccessAdmin.setPk(new
UserGroupAccessPK(sessionManager.getId(),administrator.getId(),
sampleUser.getId()));
        userGroupAccessAdmin.setApplication(sessionManager);
        userGroupAccessAdmin.setSecurityLevel(administrator);
        userGroupAccessAdmin.setUser(sampleUser);


        this.getAuthEJB().addUserGroupAccess(userGroupAccessAdmin); <=
exception happens here

where

    public void addUserGroupAccess(UserGroupAccess userGroupAccess) {
        this.baseService.getUserGroupAccessDAO().add(userGroupAccess);
    }


Several other objects are persisted in the same way, but only for this one,
that has an embedded composite PK, the exception is raised. In fact, I've
just disabled the points in the code where these objects are persisted to
keep working until I find a solution/workaround for this.

My persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<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="poc">
        <jta-data-source>poc1</jta-data-source>
        <non-jta-data-source>poc2</non-jta-data-source>
        <properties>
            <property name="openjpa.jdbc.DBDictionary"
value="org.apache.openjpa.jdbc.sql.OracleDictionary" />
            <property name="openjpa.jdbc.DBDictionary"
value="oracle(maxEmbeddedBlobSize=-1,maxEmbeddedClobSize=-1)" />
            <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
<!--             <property name="openjpa.Log" value="DefaultLevel=WARN,
Runtime=INFO, Tool=INFO, SQL=TRACE"/> -->
        </properties>
    </persistence-unit>
</persistence>

thanks


[]

Leo


On Thu, Nov 21, 2013 at 5:18 PM, Rick Curtis <curtisr7@gmail.com> wrote:

> What is the scenario that you are running when you encounter this problem?
>
>
> On Thu, Nov 21, 2013 at 9:46 AM, Leonardo K. Shikida <shikida@gmail.com
> >wrote:
>
> > tomee 1.5.2 = openJPA 2.2.0
> > tomee 1.6.0 = openJPA 2.3.0-Snapshot
> >
> > thanks!
> >
> > Leo
> >
> > []
> >
> > Leo
> >
> >
> > On Thu, Nov 21, 2013 at 1:17 PM, Rick Curtis <curtisr7@gmail.com> wrote:
> >
> > > Do you know what version of OpenJPA is in  TomeEE 1.5.2?
> > >
> > >
> > > On Wed, Nov 20, 2013 at 6:46 PM, Leonardo K. Shikida <
> shikida@gmail.com
> > > >wrote:
> > >
> > > > Hi
> > > >
> > > > My code that was working with tomee 1.5.2 (openEJB 4.5.2 I guess).
> > > >
> > > > Now I am trying to use tomee 1.6.0 (openEJB 4.6.0 I guess again).
> > > >
> > > > My class uses a primary key following this structure
> > > >
> > > > @Entity
> > > > public class UserGroupAccess implements Serializable{
> > > >
> > > >     /**
> > > >      *
> > > >      */
> > > >     private static final long serialVersionUID =
> 7233673815582184369L;
> > > >
> > > >     @ManyToOne
> > > >     @JoinColumn(name="applicationId")
> > > >     @MapsId("applicationId")
> > > >     private Application application;
> > > >
> > > >     @ManyToOne
> > > >     @JoinColumn(name="securityLevelId")
> > > >     @MapsId("securityLevelId")
> > > >     private SecurityLevel securityLevel;
> > > >
> > > >     @ManyToOne
> > > >     @JoinColumn(name="userId")
> > > >     @MapsId("userId")
> > > >     private User user;
> > > >
> > > >     @EmbeddedId
> > > >     private UserGroupAccessPK pk;
> > > > (...)
> > > > }
> > > >
> > > > and the primary key
> > > >
> > > > @Embeddable
> > > > public class UserGroupAccessPK implements Serializable{
> > > >
> > > >     /**
> > > >      *
> > > >      */
> > > >     private static final long serialVersionUID =
> 7233673815582184369L;
> > > >
> > > >     public UserGroupAccessPK(long application,
> > > >             long securityLevel, long user) {
> > > >         super();
> > > >         this.applicationId = application;
> > > >         this.securityLevelId = securityLevel;
> > > >         this.userId = user;
> > > >     }
> > > >
> > > >     public UserGroupAccessPK() {
> > > >         super();
> > > >     }
> > > >
> > > >     private long applicationId;
> > > >
> > > >     private long securityLevelId;
> > > >
> > > >     private long userId;
> > > > (...)
> > > > }
> > > >
> > > > These classes are enhanced manually with
> > > > org.apache.openjpa.enhance.PCEnhancer
> > > >
> > > > While trying to run some tests, I've got the following exception
> > > >
> > > > INFO: Starting OpenJPA 2.3.0-SNAPSHOT
> > > > Nov 20, 2013 10:31:32 PM null
> > > > INFO: Connected to Oracle version 11.11 using JDBC driver Oracle JDBC
> > > > driver version 12.1.0.1.0.
> > > > Nov 20, 2013 10:31:39 PM
> > > > org.apache.geronimo.transaction.manager.TransactionImpl
> > beforeCompletion
> > > > WARNING: Unexpected exception from beforeCompletion; transaction will
> > > roll
> > > > back
> > > > <openjpa-2.3.0-SNAPSHOT-r422266:1535082 nonfatal general error>
> > > > org.apache.openjpa.persistence.PersistenceException:
> > > > org.apache.openjpa.kernel.DetachedStateManager cannot be cast to
> > > > org.apache.openjpa.kernel.StateManagerImpl
> > > >     at
> > > >
> > >
> >
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:2027)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:527)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:512)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:413)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:262)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:252)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:328)
> > > >     at
> > > >
> > org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransactionUtil.java:76)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:231)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:181)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:272)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:267)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:90)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:306)
> > > > Caused by: java.lang.ClassCastException:
> > > > org.apache.openjpa.kernel.DetachedStateManager cannot be cast to
> > > > org.apache.openjpa.kernel.StateManagerImpl
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.jdbc.meta.FieldMapping.setPKValueFromMappedByIdField(FieldMapping.java:640)
> > > >     at
> > > >
> org.apache.openjpa.jdbc.meta.FieldMapping.insert(FieldMapping.java:622)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(AbstractUpdateManager.java:239)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:166)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:110)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:78)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:732)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
> > > >     at
> org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2203)
> > > >     at
> > > org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2101)
> > > >     at
> > > >
> > >
> >
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:2019)
> > > >     ... 17 more
> > > >
> > > > Exception in thread "main"
> javax.ejb.EJBTransactionRolledbackException:
> > > > Transaction was rolled back, presumably because setRollbackOnly was
> > > called
> > > > during a synchronization
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:379)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:310)
> > > > Caused by: javax.transaction.RollbackException: Unable to commit:
> > > > transaction marked for rollback
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:272)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:252)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:328)
> > > >     at
> > > >
> > org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransactionUtil.java:76)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:231)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:181)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:272)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:267)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:90)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:306)
> > > >     ... 3 more
> > > > Caused by:
> > > > org.apache.geronimo.transaction.manager.SetRollbackOnlyException:
> > > > setRollbackOnly() called.  See stacktrace for origin
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.setRollbackOnly(TransactionImpl.java:126)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:243)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openejb.core.TransactionSynchronizationRegistryWrapper.setRollbackOnly(TransactionSynchronizationRegistryWrapper.java:71)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.ee.RegistryManagedRuntime$TransactionManagerRegistryFacade.setRollbackOnly(RegistryManagedRuntime.java:128)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.ee.RegistryManagedRuntime.setRollbackOnly(RegistryManagedRuntime.java:74)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.ee.AutomaticManagedRuntime.setRollbackOnly(AutomaticManagedRuntime.java:274)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.kernel.BrokerImpl.setRollbackOnlyInternal(BrokerImpl.java:1670)
> > > >     at
> > > >
> > >
> >
> org.apache.openjpa.kernel.BrokerImpl.setRollbackOnly(BrokerImpl.java:1650)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.kernel.DelegatingBroker.setRollbackOnly(DelegatingBroker.java:981)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.persistence.EntityManagerImpl.setRollbackOnly(EntityManagerImpl.java:631)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.persistence.PersistenceExceptions$2.translate(PersistenceExceptions.java:77)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.openjpa.kernel.BrokerImpl.translateManagedCompletionException(BrokerImpl.java:2089)
> > > >     at
> > > >
> > >
> >
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:2027)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:527)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:512)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:413)
> > > >     at
> > > >
> > > >
> > >
> >
> org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:262)
> > > >     ... 13 more
> > > >
> > > > Any help is welcome.
> > > >
> > > > Thanks in advance.
> > > >
> > > > Leo
> > > >
> > >
> > >
> > >
> > > --
> > > *Rick Curtis*
> > >
> >
>
>
>
> --
> *Rick Curtis*
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message