테스트를 위해 Glassfish 4.0 컨테이너가 포함 된 Arquillian을 사용하고 있습니다. 지금까지, 나는 그것을 작동시킬 수 있었지만, 하나의 테스트 케이스가 계속 실패하고 나는 왜 그런지 모른다. 여기 내 테스트 코드입니다 :JavaEE CDI 테스트 : RollbackException의 원인 얻기
// 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
}
그리고이 서비스 클래스입니다 : arquillian 이것을 실행하는 경우
이// CompetenceService
@Transactional
@ApplicationScoped
public class CompetenceService {
@PersistenceContext
private EntityManager em;
public Competence save(Competence c){
return em.merge(c);
}
}
, 다음과 같은 오류가 나타납니다
이Managed bean with Transactional annotation and TxType of REQUIRED encountered exception during commit javax.transaction.RollbackException: Transaction marked for rollback
내 질문은 : 수 난 어떻게 든 잘못되고 있는지 알아 내려고? 내 첫 번째 생각은 모든 제약 조건이 만족스럽지 않다는 것입니다 (예 : @NotNull
).
전체 스택 트레이스를 얻지 못하고 테스트 실행의 끝 부분에서 오류 만 발생합니다. 출력은 다음과 같습니다.
[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.eclip[email protected]fe04c00, [email protected]e9d9c24, [email protected]d7627ce, com.sun.e[email protected]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
------------------------------------------------------------------------
콘솔이나 반품에 스택 추적이 없습니까? 나는 또한 당신의 예외를 저장하는 방법 후에 일어나는 것 같아요? – LightGuard
안녕하세요, 질문을 업데이트하면 출력됩니다. 또한 save 메소드로 인해 예외가 발생하며 이후의 명령문은 실행되지 않습니다. – bmurauer