问题描述
我有一个使用JPA/Hibernate和Google Guice的应用程序. Guice在ServletContextListener
中引导,并设置EntityManagerFactory
本身.
I have an application which uses JPA/Hibernate and Google Guice. Guice is bootstrapped in a ServletContextListener
and it sets up the EntityManagerFactory
itself.
该应用程序在Tomcat 7上运行良好,但是当我部署到JBoss AS7时,它失败了,因为JBoss决定在调用我的ServletContextListener
之前自动设置JPA.
The application works fine on Tomcat 7, but when I deploy to JBoss AS7 it fails because JBoss decides to automatically setup JPA prior to invoking my ServletContextListener
.
如何让JBoss不自动初始化JPA,而是等待我的ServletContextListener
完成它?
How can I get JBoss to not initialize JPA automatically and instead wait for my ServletContextListener
to do it?
更新
根据詹姆斯在下面提供的链接:
According to the link that James provided below:
https://docs.jboss.org/author/display/AS71/JPA + Reference + Guide#JPAReferenceGuide简介
我需要弄清楚如何禁用此自动检测"功能.
I need to figure out how to disable this "auto-detect" feature.
更新#2
可以通过在persistence.xml中添加以下属性来禁用JPA的容器管理:
Container management of JPA can be disabled by adding the following property to the persistence.xml:
<property name="jboss.as.jpa.managed" value="false" />
根据此主题,截至2012年2月该功能仅在每晚构建中可用.
According to this topic, as of February 2012 this functionality is only available in a nightly build.
推荐答案
JBoss AS7是完整的Java EE服务器.这意味着JPA实现与它捆绑在一起.在Tomcat中,您必须提供自己的JPA实现,并且实际上要像在Java SE中那样运行JPA.
JBoss AS7 is a full Java EE server. That means that a JPA implementation comes bundled with it. In Tomcat you have to provide your own JPA implementation and are essentially running JPA like you would in Java SE.
我建议您阅读 JPA参考文档,以获取有关AS7.
I would recommend you read the JPA reference documentation for AS7.
您还将获得CDI,因此不需要Guice.您可能可以使用Guice而不是CDI,但说实话我无法告诉您如何:-)
You also get CDI so there is no real need for Guice. You could probably use Guice instead of CDI, but honestly I couldn't tell you how :-)
这篇关于JBoss AS7自动加载JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!