简体   繁体   中英

Spring Data, Hibernate 4.1.1 and Spring JTA Transaction Manager

I am in the process of developing a web application and decided that using spring-data would be a good idea. To be fair it makes life extremely easy and the DAO layer very thin.

The issue I am have is to do with persisting data. When I use a JPATransactionManager the persistence works as expected. But I need to use a JTATransactionManager. When I use this it appears that the transaction looks fine but the hibernate flush does not seem to be associated with the tx commit

DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-2) Creating new transaction with name [com.clubgroups.user.registration.service.impl.UserRegistrationServiceImpl.registerUser]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''

DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-2) Participating in existing transaction

DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-2) Initiating transaction commit

Above is the debug message that confirms that the transaction is being committed. But the data does not seem to be flushed to the database.

I initialize the transaction manager like this:

@Bean
public JpaTransactionManager transactionManager() {
    JtaTransactionManager transactionManager = new JtaTransactionManager();       

    return transactionManager;
}

Any help would be great.

I am a bit puzzled about your JTA setup as it's highly unusual. First, have a look at the reference documentation on how to setup JTA transactions correctly. Simply instantiating the JtaTransactionManager doesn't work as you need to obtain a UserTransaction from JNDI by some means. You should see an error popping up if you call afterPropertiesSet() in your @Bean method as this will unveil the missing configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM