Persistence deployment issue

谁说我不能喝 提交于 2019-12-23 05:32:15

问题


I have a hibernate project, which uses JPA.

my persistence.xml contents is as follows:

<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="Demo-PU" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>java:/DemoDS</non-jta-data-source> 
    <class>com.demo.framework.entity.ReportDefinitionEntity</class> 
    <properties>

<!--  Database connection -->
  <property name="hibernate.connection.url" value="jdbc:mysql://192.168.9.110:3306/demoDB" />
  <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
  <property name="hibernate.connection.username" value="root" />
  <property name="hibernate.connection.password" value="root" />

 <!--  Hibernate dialect  -->
  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<!--  Output goodies
  -->
  <property name="hibernate.query.jpaql_strict_compliance" value="true" />
  <property name="hibernate.format_sql" value="true" />
  <property name="hibernate.use_sql_comments" value="false" />
   <!--  Cache
  -->
  <property name="hibernate.jdbc.batch_versioned_data" value="true" />
  <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />

    </properties>
  </persistence-unit>
</persistence>

Now when I run it using eclipse I don't have a problem, but when I deploy it in Jboss, I get the below error:

ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=#Demo-PU state=Create java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider

And here is the list of Jar that I have

activation.jar
antlr-2.7.6.jar
asm-attrs.jar
asm.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-logging-1.1.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate-tools.jar
hibernate3.jar
javassist.jar
javax.persistence.jar
jdbc2_0-stdext.jar
jta.jar
mysql-connector-java-5.0.5-bin.jar
xml-writer.jar

How can I resolve this issue?


回答1:


The ClassCastException is caused by having two copies of the javax.persistence APIs in your system (one in the common classloader provided by JBoss and the one in your app). When running on JBoss, you are just not supposed to provide this API in your application, don't package it.

By the way, it seems you're using a JPA 2.0 persistence.xml but I'm not convinced you're using the JPA 2.0 implemenation of Hibernate (actually, you seem to be using a pretty old version since I can see commons-logging.jar). You should probably fix that i.e. use the 1.0 version of persistence.xml.

Actually, you should very likely use a different persistence.xml when running on JBoss (using a JTA entity manager and a jta-data-source). And it seems weird to mix data source usage and Hibernate built-in connection pool.



来源:https://stackoverflow.com/questions/3537306/persistence-deployment-issue

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