org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is bitronix.tm.internal.BitronixRollbackException: RuntimeException thrown during beforeCompletion cycle caused transaction rollback There's some of the configuration I'm using (please see github for all of it) @Bean public JPAConfig jpaConfig() throws Exception { Properties p = new Properties(); p.setProperty("hibernate.dialect", HSQLDialect.class.getName()); p.setProperty("hibernate.hbm2ddl.auto", "create-drop"); p.setProperty("hibernate.showsql", "true"); return new JPAConfig(p, datasource(), true, "com.kloudtek.ktspring"); } public DataSource datasource() throws Exception { PoolingDataSource dataSource = new PoolingDataSource(); dataSource.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource"); dataSource.setUniqueName("hsqldb"); dataSource.setMaxPoolSize(5); dataSource.setAllowLocalTransactions(true); dataSource.getDriverProperties().setProperty("driverClassName", "org.hsqldb.jdbcDriver"); dataSource.getDriverProperties().setProperty("url", "jdbc:hsqldb:mem:test?hsqldb.applog=3"); dataSource.getDriverProperties().setProperty("user", "sa"); dataSource.getDriverProperties().setProperty("password", "theSaPassword"); try (Connection connection = dataSource.getConnection()) { try (Statement st = connection.createStatement()) { st.execute("SET DATABASE EVENT LOG SQL LEVEL 3"); } } return dataSource; } @Bean public JPAParams jpaParams() { Properties p = new Properties(); p.setProperty("hibernate.current_session_context_class", "jta"); p.setProperty("hibernate.transaction.jta.platform", BitronixJtaPlatform.class.getName()); p.setProperty("hibernate.connection.autocommit", "false"); return new JPAParams(p); } @Bean(destroyMethod = "shutdown") public BitronixTransactionManager bitronixTransactionManager() { return TransactionManagerServices.getTransactionManager(); } @Bean public PlatformTransactionManager transactionManager() { return new JtaTransactionManager(bitronixTransactionManager(), bitronixTransactionManager()); } @Bean public LocalContainerEntityManagerFactoryBean entityManager() { LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean(); if (config.isJtaDatasource()) { entityManager.setJtaDataSource(config.getDataSource()); } else { entityManager.setDataSource(config.getDataSource()); } Properties p = new Properties(); p.putAll(config.getJpaProperties()); if (jpaParamsList != null) { for (JPAParams jpaParams : jpaParamsList) { p.putAll(jpaParams.getProperties()); } } entityManager.setJpaProperties(p); entityManager.setPackagesToScan(config.getPackageToScan()); entityManager.setPersistenceProvider(new HibernatePersistenceProvider()); return entityManager; } After a lot of debugging, it looks like the entitymanager is being closed by spring. This seems to happen because EntityManagerHolder gets registered with the transaction synchronization, but I would have though this should only happen in the case of a JPA transaction but NOT when JTA is used ........... going to continue investigating at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:347)

Searched on Google with the first line of a JAVA stack trace?

We can recommend more relevant solutions and speed up debugging when you paste your entire stack trace with the exception message. Try a sample exception.

Recommended solutions based on your search

Samebug tips

Do you know how to solve this issue? Write a tip to help other users and build your expert profile.

Solutions on the web

via Stack Overflow by Yannick Menager
, 1 year ago
JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is bitronix.tm.internal.BitronixRollbackException: RuntimeException thrown during beforeCompletion cycle caused transaction rollback There's some of the
org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is bitronix.tm.internal.BitronixRollbackException: RuntimeException thrown during beforeCompletion cycle caused transaction rollback There's some of the configuration I'm using (please see github for all of it) @Bean public JPAConfig jpaConfig() throws Exception { Properties p = new Properties(); p.setProperty("hibernate.dialect", HSQLDialect.class.getName()); p.setProperty("hibernate.hbm2ddl.auto", "create-drop"); p.setProperty("hibernate.showsql", "true"); return new JPAConfig(p, datasource(), true, "com.kloudtek.ktspring"); } public DataSource datasource() throws Exception { PoolingDataSource dataSource = new PoolingDataSource(); dataSource.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource"); dataSource.setUniqueName("hsqldb"); dataSource.setMaxPoolSize(5); dataSource.setAllowLocalTransactions(true); dataSource.getDriverProperties().setProperty("driverClassName", "org.hsqldb.jdbcDriver"); dataSource.getDriverProperties().setProperty("url", "jdbc:hsqldb:mem:test?hsqldb.applog=3"); dataSource.getDriverProperties().setProperty("user", "sa"); dataSource.getDriverProperties().setProperty("password", "theSaPassword"); try (Connection connection = dataSource.getConnection()) { try (Statement st = connection.createStatement()) { st.execute("SET DATABASE EVENT LOG SQL LEVEL 3"); } } return dataSource; } @Bean public JPAParams jpaParams() { Properties p = new Properties(); p.setProperty("hibernate.current_session_context_class", "jta"); p.setProperty("hibernate.transaction.jta.platform", BitronixJtaPlatform.class.getName()); p.setProperty("hibernate.connection.autocommit", "false"); return new JPAParams(p); } @Bean(destroyMethod = "shutdown") public BitronixTransactionManager bitronixTransactionManager() { return TransactionManagerServices.getTransactionManager(); } @Bean public PlatformTransactionManager transactionManager() { return new JtaTransactionManager(bitronixTransactionManager(), bitronixTransactionManager()); } @Bean public LocalContainerEntityManagerFactoryBean entityManager() { LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean(); if (config.isJtaDatasource()) { entityManager.setJtaDataSource(config.getDataSource()); } else { entityManager.setDataSource(config.getDataSource()); } Properties p = new Properties(); p.putAll(config.getJpaProperties()); if (jpaParamsList != null) { for (JPAParams jpaParams : jpaParamsList) { p.putAll(jpaParams.getProperties()); } } entityManager.setJpaProperties(p); entityManager.setPackagesToScan(config.getPackageToScan()); entityManager.setPersistenceProvider(new HibernatePersistenceProvider()); return entityManager; } After a lot of debugging, it looks like the entitymanager is being closed by spring. This seems to happen because EntityManagerHolder gets registered with the transaction synchronization, but I would have though this should only happen in the case of a JPA transaction but NOT when JTA is used ........... going to continue investigating at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:347)
at com.sun.proxy.$Proxy44.close(Unknown Source)
at org.springframework.orm.jpa.EntityManagerFactoryUtils.closeEntityManager(EntityManagerFactoryUtils.java:438)
at org.springframework.orm.jpa.EntityManagerFactoryUtils$TransactionalEntityManagerSynchronization.releaseResource(EntityManagerFactoryUtils.java:511)
at org.springframework.transaction.support.ResourceHolderSynchronization.beforeCompletion(ResourceHolderSynchronization.java:77)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCompletion(TransactionSynchronizationUtils.java:106)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion(AbstractPlatformTransactionManager.java:945)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:745)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)

Users with the same issue

You are the first who have seen this exception. Write a tip to help other users and build your expert profile.

Write tip

Know the solutions? Share your knowledge to help other developers to debug faster.