1
votes

I'm upgrading jboss 4.3 to jboss 6.1 EAP. The application was using hibernate3.jar to load hibernate classes in 4.3. The 6.1 EAP is shared by different applications and the hibernate4.jar is available in the global modules of JBOSS (as it is used by other applications). I tried to add hibernate3.jar as dependecy in jboss for my application and I added org.hibernate as a dependency in jboss-deployment-structure.xml. But I still see hibernate4 classes loaded instead of 3 for my application. How can I make it load only hibernate3?

Below is the log:

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

1 Answers

0
votes

Only recommended that the version of Hibernate shipped with the EAP release.

The below may facilitate the use of Hibernate 3 JPA with your application.

Create the 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

NOTE Starting with Hibernate 3.6, hibernate-annotations.jar should NOT be included as the required classes are present in hibernate-core.jar.

Copy the module.xml and the jars specified as resource-root path entries to /org/hibernate/3 3 in the directory path corresponds to the slot

In persistence.xml, specify the jboss.as.jpa.providerModule property

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

You may need to specify the older class (HibernatePersistence) in your persistence.xml as shown above

If your application depends on Hibernate specific classes, you may need to add a dependency on the Hibernate 3 module ().

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