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)

tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Spring + hibernate JPA + JTA (Atomikos / Bitronix) failing

    Stack Overflow | 9 months ago | Yannick Menager
    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)

    Root Cause Analysis

    1. 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()
    2. com.sun.proxy
      $Proxy44.close
      1. com.sun.proxy.$Proxy44.close(Unknown Source)
      1 frame
    3. Spring ORM
      EntityManagerFactoryUtils$TransactionalEntityManagerSynchronization.releaseResource
      1. org.springframework.orm.jpa.EntityManagerFactoryUtils.closeEntityManager(EntityManagerFactoryUtils.java:438)
      2. org.springframework.orm.jpa.EntityManagerFactoryUtils$TransactionalEntityManagerSynchronization.releaseResource(EntityManagerFactoryUtils.java:511)
      3. org.springframework.orm.jpa.EntityManagerFactoryUtils$TransactionalEntityManagerSynchronization.releaseResource(EntityManagerFactoryUtils.java:456)
      3 frames
    4. Spring Tx
      TransactionTemplate.execute
      1. org.springframework.transaction.support.ResourceHolderSynchronization.beforeCompletion(ResourceHolderSynchronization.java:77)
      2. org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCompletion(TransactionSynchronizationUtils.java:106)
      3. org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion(AbstractPlatformTransactionManager.java:945)
      4. org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:745)
      5. org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
      6. org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:150)
      6 frames