简体   繁体   中英

Using Spring + Hibernate Transactional cache in Tomcat?

It seems that Hibernate transactional cache mode requires the use of a JTA transaction manager. In an app server such as Glassfish, Weblogic, etc, Spring can use the JTA transaction manager. Tomcat does not have a JTA transaction manager.

Is there one that people use in this scenario? Or do people just not use transactional cache mode with Tomcat?

It depends on you ORM implementation, for example for JPA Spring has a transaction manager for using outside Java EE containers. here's how you declare it:

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

I usually use annotations to demarcate transaction boundaries (with @Transaction), to do this you just have to add to the configuration file this other line:

<tx:annotation-driven transaction-manager="transactionManager" />

present in this XSD namespace: " http://www.springframework.org/schema/tx "

Atomikos 是一种 JTA 事务管理器,可以与您的应用程序捆绑在一起以在 Tomcat 部署中工作。

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