Question

I'm using Arquillian with an embedded Glassfish 4.0 container for testing. So far, I managed to get it to work, but one test case keeps failing and I don't know why. Here is my Test code:

// Test Class
    @Inject
    private CompetenceService competenceService;

    @Test
    public void createSingleCompetence() {
        Competence c = new Competence();
        // fill the competence with data
        c = competenceService.save(c); // throws a RollbackException
        // some testing assertions
    }

And this is the Service Class:

// CompetenceService
@Transactional
@ApplicationScoped
public class CompetenceService {

    @PersistenceContext
    private EntityManager em;

    public Competence save(Competence c){
        return em.merge(c);
    }
}

When running this with arquillian, following error appears:

 Managed bean with Transactional annotation and TxType of REQUIRED encountered exception during commit javax.transaction.RollbackException: Transaction marked for rollback

My question is: can I somehow figure out what is going wrong? My first thought was that not all constraints were satisfied (like @NotNull), but I ruled that out now.

I don't get a full stacktrace, only the error at the end of the testrun. Here is the output:

[Competence test competence]
Aug 07, 2013 8:28:57 AM org.glassfish.cdi.transaction.TransactionalInterceptorRequired transactional
INFO: In REQUIRED TransactionalInterceptor
Aug 07, 2013 8:28:57 AM org.glassfish.cdi.transaction.TransactionalInterceptorRequired transactional
INFO: Managed bean with Transactional annotation and TxType of REQUIRED called outside a transaction context.  Beginning a transaction...
Aug 07, 2013 8:28:57 AM org.glassfish.cdi.transaction.TransactionalInterceptorBase markRollbackIfActiveTransaction
INFO: About to setRollbackOnly from @Transactional interceptor on transaction:JavaEETransactionImpl: txId=1 nonXAResource=1 jtsTx=null localTxStatus=0 syncs=[org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper$1@fe04c00, org.eclipse.persistence.transaction.JTASynchronizationListener@4e9d9c24, org.eclipse.persistence.transaction.JTASynchronizationListener@4d7627ce, com.sun.enterprise.resource.pool.PoolManagerImpl$SynchronizationListener@82f6d1d]
Aug 07, 2013 8:28:57 AM org.glassfish.cdi.transaction.TransactionalInterceptorRequired transactional
INFO: Managed bean with Transactional annotation and TxType of REQUIRED encountered exception during commit javax.transaction.RollbackException: Transaction marked for rollback.
Aug 07, 2013 8:28:58 AM org.glassfish.persistence.common.Java2DBProcessorHelper executeDDLs
WARNING: PER01000: Got SQLException executing statement "ALTER TABLE COMPETENCECATEGORY DROP CONSTRAINT CMPTWNNGNSTNCNTTYD": java.sql.SQLSyntaxErrorException: ALTER TABLE failed. There is no constraint 'APP.CMPTWNNGNSTNCNTTYD' on table '"APP"."COMPETENCECATEGORY"'. 
PlainTextActionReporterSUCCESS
PER01003: Deployment encountered SQL Exceptions:
PER01000: Got SQLException executing statement "ALTER TABLE COMPETENCECATEGORY DROP CONSTRAINT CMPTWNNGNSTNCNTTYD": java.sql.SQLSyntaxErrorException: ALTER TABLE failed. There is no constraint 'APP.CMPTWNNGNSTNCNTTYD' on table '"APP"."COMPETENCECATEGORY"'. Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 23.032 sec <<< FAILURE!
Aug 07, 2013 8:29:01 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
JdbcRuntimeExtension,  getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource]
Aug 07, 2013 8:29:01 AM com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl sendStopToResourceAdapter
INFO: RAR7094: __ds_jdbc_ra shutdown successful.
Aug 07, 2013 8:29:01 AM com.sun.enterprise.v3.server.AppServerStartup stop
INFO: Shutdown procedure finished

Results :

Tests in error: 
  createSingleCompetence(at.seresunit.outtasking.test.CompetenceTest): Managed bean with Transactional annotation and TxType of REQUIRED encountered exception during commit javax.transaction.RollbackException: Transaction marked for rollback.

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Était-ce utile?

La solution

It's not a problem with Arquillian.

Since you can't find the exception in the StackTrace I suppose the original Exception is wrapped into a RollbackException. According to the JTA 1.2 specification, any unchecked Exception will automatically rollback the transaction.

Can you confirm that no unchecked Exception (such as a RuntimeException, Nullpointer etc.) is thrown in any of your underlying methods - might even come from some custom validator. This is the JTA 1.2 spec for further reference: https://java.net/projects/jta-spec/sources/spec-source-repository/content/jta-1_2-spec_v2.pdf?rev=14

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top