持久性部署问题 [英] Persistence deployment issue

查看:97
本文介绍了持久性部署问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用JPA的hibernate项目。



我的persistence.xml内容如下:

 < persistence version =2.0xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http://www.w3 .org / 2001 / XMLSchema-instancexsi:schemaLocation =http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd\"> ; 
< persistence-unit name =Demo-PUtransaction-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>
<属性>

<! - 数据库连接 - >
< property name =hibernate.connection.driver_classvalue =com.mysql.jdbc.Driver/>
< property name =hibernate.connection.usernamevalue =root/>
< property name =hibernate.connection.passwordvalue =root/>

<! - Hibernate方言 - >
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQLDialect/>
<! - 输出好吃的东西
- >
< property name =hibernate.query.jpaql_strict_compliancevalue =true/>
< property name =hibernate.format_sqlvalue =true/>
< property name =hibernate.use_sql_commentsvalue =false/>
<! - 缓存
- >
< property name =hibernate.jdbc.batch_versioned_datavalue =true/>
< property name =hibernate.cache.provider_classvalue =org.hibernate.cache.HashtableCacheProvider/>

< / properties>
< / persistence-unit>
< /余辉>

现在当我使用eclipse运行它时,我没有问题,但是当我部署它时Jboss,我得到以下错误:


错误[AbstractKernelController]错误
安装到开始:
名称=持久性.unit:unitName =#Demo-PU
state =创建
java.lang.ClassCastException:
org.hibernate.ejb.HibernatePersistence
不能转换为
javax .persistence.spi.PersistenceProvider


以下是我拥有的Jar列表

  activation.jar 
antlr-2.7.6.jar
asm-attrs.jar
asm.jar
cglib-2.1 .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
j ta.jar
mysql-connector-java-5.0.5-bin.jar
xml-writer.jar

我该如何解决这个问题?

解决方案 是由系统中的 javax.persistence API的两个副本(一个在JBoss提供的常用类加载器中,另一个在您的应用中)。当在JBoss上运行时,你只是不应该在你的应用程序中提供这个API,不要打包它。



顺便说一下,你似乎在使用JPA 2.0 persistence.xml 但我不相信你使用的是Hibernate的JPA 2.0实现(实际上,因为我可以看到你似乎正在使用一个很老的版本公地logging.jar )。你应该修正这个问题,即使用1.0版本的 persistence.xml

其实,你应该很可能使用在JBoss上运行时(使用JTA实体管理器和 jta-data-source ),不同的 persistence.xml 。混合使用数据源和Hibernate内置连接池似乎很奇怪。


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?

解决方案

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.

这篇关于持久性部署问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆