Hibernate3.jar未在Jboss 6.1 EAP中加载(从JBOSS 4.3迁移到6.1 EAP)

时间:2017-04-28 11:36:14

标签: hibernate jboss6.x

我将jboss 4.3升级到jboss 6.1 EAP。该应用程序使用hibernate3.jar在4.3中加载hibernate类。 6.1 EAP由不同的应用程序共享,hibernate4.jar在JBOSS的全局模块中可用(因为它被其他应用程序使用)。我尝试在jboss中为我的应用程序添加hibernate3.jar作为依赖,并在org.hibernate中添加jboss-deployment-structure.xml作为依赖项。但我仍然看到hibernate4类加载而不是3为我的应用程序。如何才能加载hibernate3?

以下是日志:

Caused by: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
    at com.arbitron.sms.common.dao.JobDAOImpl.logToAuditProcess(JobDAOImpl.java:388) [mr.jar:]
    at com.arbitron.sms.sample.job.DemoValuesAverageReportJob.execute(DemoValuesAverageReportJob.java:47) [mr.jar:]
    at com.arbitron.sms.common.processing.ReportMessageBean.onMessage(ReportMessageBean.java:41) [mr.jar:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_11]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_11]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_11]
    at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_11]
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2]
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2]
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58) [jboss-as-ee-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2]
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2]
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58) [jboss-as-ee-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-2.jar:1.1.1.Final-redhat-2]

1 个答案:

答案 0 :(得分:0)

仅推荐使用EAP版本附带的Hibernate版本。

以下内容可能有助于在您的应用程序中使用Hibernate 3 JPA。

创建Hibernate 3 module.xml

<module xmlns="urn:jboss:module:1.1" name="org.hibernate" slot="3">
    <resources>
        <resource-root path="hibernate-annotations.jar"/>
        <resource-root path="hibernate-commons-annotations.jar"/>
        <resource-root path="hibernate-core.jar"/>
        <resource-root path="hibernate-entitymanager.jar"/>
        <resource-root path="hibernate-validator.jar"/>
    </resources>
    <dependencies>
        <module name="asm.asm"/>
        <module name="javax.api"/>
        <module name="javax.annotation.api"/>
        <module name="javax.enterprise.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.validation.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="org.antlr"/>
        <module name="org.apache.commons.collections"/>
        <module name="org.dom4j"/>
        <module name="org.javassist"/>
        <module name="org.jboss.as.jpa.hibernate" slot="3"/>
        <module name="org.jboss.as.jpa.spi"/>
        <module name="org.jboss.as.jpa.util"/>
        <module name="org.jboss.jandex"/>
        <module name="org.jboss.logging"/>
        <module name="org.jboss.vfs"/>
        <module name="org.slf4j"/>
    </dependencies>
</module

注意从Hibernate 3.6开始,不应包含hibernate-annotations.jar,因为hibernate-core.jar中存在必需的类。

将module.xml和指定为资源根路径条目的jar复制到/ org / hibernate / 3  目录路径中的3对应于插槽

在persistence.xml中,指定jboss.as.jpa.providerModule属性

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
        <persistence-unit name="example_pu" transaction-type="JTA">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>...</jta-data-source>
                <properties>
                        <property name="jboss.as.jpa.providerModule" value="org.hibernate:3"/> <!-- module:slot -->
                </properties>
        </persistence-unit>
</persistence>

您可能需要在persistence.xml中指定较旧的类(HibernatePersistence),如上所示

如果您的应用程序依赖于Hibernate特定的类,您可能需要在Hibernate 3模块()上添加依赖项。

请参阅https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide#JPAReferenceGuide-PackagingtheHibernate3.5orgreater3.xJPApersistenceproviderwithyourapplication