jboss 7.0.1 hibernate javax.persistence.PersistenceException:没有 EntityManager 的持久性提供程序

发布于 2024-12-05 13:03:58 字数 7321 浏览 1 评论 0原文

我的休眠应用程序在 jboss-as-7.0.0.Final 中成功运行,我将其移至 jboss-as-7.0.1.Final 并且我开始收到这些错误,

17:42:42,725 ERROR [com.mycompany.myapp.common.persistence.HibernateUtil] (MSC service thread 1-12) Initial SessionFactory lookup failed.: javax.persistence.PersistenceException: No Persistence provider for EntityManager named primary2
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
at com.mycompany.myapp.common.persistence.HibernateUtil.<clinit>(HibernateUtil.java:35) [classes:]
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:84) [classes:]
at com.mycompany.myapp.common.jms.JMSListenerServletTemplate.init(JMSListenerServletTemplate.java:41) [classes:]
at com.mycompany.myapp.common.jms.JMSAnywhereServlet.init(JMSAnywhereServlet.java:179) [classes:]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]

17:42:42,732 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp]] (MSC service thread 1-12) StandardWrapper.Throwable: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:92) [classes:]
at com.mycompany.myapp.common.jms.JMSListenerServletTemplate.init(JMSListenerServletTemplate.java:41) [classes:]
at com.mycompany.myapp.common.jms.JMSAnywhereServlet.init(JMSAnywhereServlet.java:179) [classes:]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]

17:42:42,734 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp]] (MSC service thread 1-12) Servlet /myapp threw load() exception: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:92) [classes:]
at com.mycompany.myapp.common.jms.JMSListenerServletTemplate.init(JMSListenerServletTemplate.java:41) [classes:]
at com.mycompany.myapp.common.jms.JMSAnywhereServlet.init(JMSAnywhereServlet.java:179) [classes:]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]

我的 persistence.xml 看起来像

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
   xmlns="http://java.sun.com/xml/ns/persistence"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
    http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   <persistence-unit name="primary">
  <non-jta-data-source>java:jboss/datasources/MySqlDS</non-jta-data-source>

  <properties>

     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
     <property name="hibernate.ejb.interceptor.session_scoped" value="com.clairvista.liveexpert.common.persistence.BusinessObjectInterceptor"/>
           </properties>

我的 pom.xml 看起来像

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.0.0.Beta5</version>
  </dependency>

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>3.2.0.Final</version>
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.0.0.Beta5</version>
  </dependency>

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-infinispan</artifactId>
    <version>4.0.0.Beta5</version>
  </dependency>

抛出这些错误的代码,看起来

        entityManagerFactory = Persistence.createEntityManagerFactory("primary");

我不确定发生了什么 - 这个应用程序正在 jboss-as-7.0.0.Final 中工作。我知道 7.0.1 对应用程序中捆绑的 hibernate 版本有更好的支持 - 但我不确定这与我的问题有何关系,因为我想使用与容器捆绑的 hibernate 版本。有什么想法吗?

My hibernate app was running successfully in jboss-as-7.0.0.Final, I moved it to jboss-as-7.0.1.Final and I started receiving these errors

17:42:42,725 ERROR [com.mycompany.myapp.common.persistence.HibernateUtil] (MSC service thread 1-12) Initial SessionFactory lookup failed.: javax.persistence.PersistenceException: No Persistence provider for EntityManager named primary2
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
at com.mycompany.myapp.common.persistence.HibernateUtil.<clinit>(HibernateUtil.java:35) [classes:]
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:84) [classes:]
at com.mycompany.myapp.common.jms.JMSListenerServletTemplate.init(JMSListenerServletTemplate.java:41) [classes:]
at com.mycompany.myapp.common.jms.JMSAnywhereServlet.init(JMSAnywhereServlet.java:179) [classes:]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]

17:42:42,732 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp]] (MSC service thread 1-12) StandardWrapper.Throwable: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:92) [classes:]
at com.mycompany.myapp.common.jms.JMSListenerServletTemplate.init(JMSListenerServletTemplate.java:41) [classes:]
at com.mycompany.myapp.common.jms.JMSAnywhereServlet.init(JMSAnywhereServlet.java:179) [classes:]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]

17:42:42,734 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp]] (MSC service thread 1-12) Servlet /myapp threw load() exception: java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.myapp.common.persistence.HibernateUtil
at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:92) [classes:]
at com.mycompany.myapp.common.jms.JMSListenerServletTemplate.init(JMSListenerServletTemplate.java:41) [classes:]
at com.mycompany.myapp.common.jms.JMSAnywhereServlet.init(JMSAnywhereServlet.java:179) [classes:]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]

my persistence.xml looks like

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
   xmlns="http://java.sun.com/xml/ns/persistence"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
    http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   <persistence-unit name="primary">
  <non-jta-data-source>java:jboss/datasources/MySqlDS</non-jta-data-source>

  <properties>

     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
     <property name="hibernate.ejb.interceptor.session_scoped" value="com.clairvista.liveexpert.common.persistence.BusinessObjectInterceptor"/>
           </properties>

and my pom.xml looks like

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.0.0.Beta5</version>
  </dependency>

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>3.2.0.Final</version>
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.0.0.Beta5</version>
  </dependency>

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-infinispan</artifactId>
    <version>4.0.0.Beta5</version>
  </dependency>

the code that throws these errors looks like

        entityManagerFactory = Persistence.createEntityManagerFactory("primary");

I'm not sure what's going on - this app was working in jboss-as-7.0.0.Final. I know 7.0.1 has better support for hibernate versions bundled within applications - but I'm not sure how this relates to my problem as I'd like to use the version of hibernate that comes bundled with the container. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转身泪倾城 2024-12-12 13:03:58

我们的 pom.xml 中没有任何 hibernate- 依赖项,因为 JBoss 已经有了它们。您只需要设置为提供的 JBoss 7 库。

<dependency>
    <groupId>org.jboss.spec</groupId>
    <artifactId>jboss-javaee-6.0</artifactId>
    <version>2.0.0.Final</version>
    <type>pom</type>
    <scope>provided</scope>
</dependency>

NoClassDefFoundError 通常与类或接口在类路径中出现两次有关,因此类加载器不知道该使用哪一个。

We don't have any of the hibernate- dependencies in our pom.xml since JBoss already has them. You just need the JBoss 7 libraries which are set to provided.

<dependency>
    <groupId>org.jboss.spec</groupId>
    <artifactId>jboss-javaee-6.0</artifactId>
    <version>2.0.0.Final</version>
    <type>pom</type>
    <scope>provided</scope>
</dependency>

The NoClassDefFoundError usually relates to a class or interface being twice in the classpath, so the class loader does not know, which one to use.

合久必婚 2024-12-12 13:03:58

错误显示“没有名为 Primary2 的 EntityManager 的持久性提供程序”

,但您的 persistence.xml 将单元命名为“primary”(没有后缀 2):

<persistence-unit name="primary">

这可能是问题所在吗?

The error says "No Persistence provider for EntityManager named primary2"

but your persistence.xml names the unit "primary" (without the suffix 2):

<persistence-unit name="primary">

Can this be the issue?

謌踐踏愛綪 2024-12-12 13:03:58

您应该将 hibernate 依赖项的所有 设置为 provided,因为它包含在 JBoss 7 中。

例如,对于第一个依赖项,您应该编写:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.0.0.Beta5</version>
    <scope>provided</scope>
</dependency>

You should set all the <scope>s of your hibernate dependencies to provided as it is included in JBoss 7.

For example, with your first dependency, you should write :

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.0.0.Beta5</version>
    <scope>provided</scope>
</dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文