Options for using Spring, Hibernate, JPA, and Tomcat with multiple Databases

半城伤御伤魂 提交于 2019-12-12 18:54:59

问题


I have a java web app running under Spring 2.5.6, Hibernate 3.4 (with Hibernate as the JPA provider), and Tomcat 6. I have it working with one DB schema / persistence unit but now need to connect to 2 schemas / persistence units. Can I do this without moving to a J2EE container such as JBoss or Glassfish? Will I need to use something like JOTM and global / XA transactions?


回答1:


If you need to access multiple transactional resources within the same transaction, you'll need JTA and thus a JTA transaction manager. At the Spring level, this will mean using a JtaTransactionManager instead of your JpaTransactionManager. And if you don't want to move to a real Java EE app server, you'll have indeed to use a standalone transaction manager such as JOTM or Atomikos. I prefer the later but, personally, I would just move to GlassFish.




回答2:


If you are using Tomcat with spring/hibernate, then use JBoss's Transaction Manager to create JTA transaction manager bean.

Here is a short tutorial http://ingenious-camel.blogspot.com/2012/01/how-to-use-jboss-transactions-in-spring.html



来源:https://stackoverflow.com/questions/3113775/options-for-using-spring-hibernate-jpa-and-tomcat-with-multiple-databases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!