使用Spring,Hibernate,JPA和Tomcat以及多个数据库的选项 [英] Options for using Spring, Hibernate, JPA, and Tomcat with multiple Databases
问题描述
我有一个在Spring 2.5.6下运行的Java Web应用程序,Hibernate 3.4(以Hibernate作为JPA提供程序)和Tomcat 6.我使用一个数据库模式/持久性单元工作,但现在需要连接2个模式/持久性单元。我可以在不移动到J2EE容器(如JBoss或Glassfish)的情况下执行此操作吗?我需要使用类似JOTM和global / XA事务吗?
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?
推荐答案
如果您需要访问相同的多个事务资源交易,你需要JTA,因此需要一个JTA交易管理器。在Spring级别,这意味着使用 JtaTransactionManager
而不是您的 JpaTransactionManager
。如果您不想转移到真正的Java EE应用服务器,那么您的确可以使用独立的事务管理器,如JOTM或Atomikos。我更喜欢后面的,但个人而言,我会转向GlassFish。
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.
这篇关于使用Spring,Hibernate,JPA和Tomcat以及多个数据库的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!