开发者

jboss 7.0.1 hibernate javax.persistence.PersistenceException: No Persistence provider for EntityManager

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.servic开发者_高级运维e.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?


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.


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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜