5 Replies Latest reply on Jan 27, 2006 12:31 PM by ldecaro

    Configuring Hibernate service

    joydeep

      Hi,

      I've configured Hibernate service for one of my application. My jboss-service.xml in the sar file looks like following:



      jboss.jca:service=RARDeployer
      com/edhand/example1/Order.hbm.xml,com/edhand/example1/Item.hbm.xml
      java:/hibertest
      java:/example1DS
      net.sf.hibernate.dialect.HSQLDialect
      true
      false
      UserTransaction
      net.sf.hibernate.transaction.JTATransactionFactory
      net.sf.hibernate.transaction.JBossTransactionManagerLookup




      Hibernate is configured to use default UserTransaction of jboss. I'm getting the following exception at JTATransaction.begin() method:
      java.lang.ClassCastException: org.jboss.tm.usertx.client.ServerVMClientUserTransaction
      at net.sf.hibernate.transaction.JTATransaction.begin(JTATransaction.java:132)
      at net.sf.hibernate.transaction.JTATransactionFactory.beginTransaction(JTATransactionFactory.java:58)
      at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2195)
      at com.edhand.example1.ItemService.addItem(Unknown Source)
      at com.edhand.example1.ItemServicesEJB.addItem(ItemServicesEJB.java:67)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:297)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)

      The return type of the begin() method is javax.transaction.UserTransaction

      I've checked that the returned class org.jboss.tm.usertx.client.ServerVMClientUserTransaction implements javax.transaction.UserTransaction, hence fully compatible with it. I'm at a loss to understand the reason for the ClassCastException. The class javax.transaction.UserTransaction is present in jboss-j2ee.jar and is loaded by the server.

      Please help!!

      Thanks,
      Joydeep

        • 1. Re: Configuring Hibernate service
          joydeep

          Some clarifications:

          The exact problem is that the method JTATransaction.begin() internally invokes the following method:

          initialcontext.lookup("UserTransaction");

          This method expects a return type of javax.transaction.UserTransaction

          and the lookup returns the following class:

          org.jboss.tm.usertx.client.ServerVMClientUserTransaction

          I'm getting the ClassCastException at this point.

          But I've checked that both the above mentioned classes are compatible.

          I really don't understand the reason for this exception. Can it be because the class javax.transaction.UserTransaction is not loaded by the server?
          But this class is present in jboss-j2ee.jar which in turn is present at the lib directory of my server.

          Please Help!!!

          Joydeep

          • 2. Re: Configuring Hibernate service
            aloubyansky

            It looks like a classloading issue. What classes/jars are in the sar package?

            • 3. Re: Configuring Hibernate service
              joydeep

              I have only hibernate mapping files in the sar package. But the EAR contains some libraries for hibernate. My application.xml looks as follows:

              <?xml version="1.0" encoding="UTF-8"?>

              <!DOCTYPE application PUBLIC
              '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN'
              'http://java.sun.com/dtd/application_1_3.dtd'>


              <display-name>Hibernate example</display-name>
              Hibernate example


              <web-uri>example1.war</web-uri>
              <context-root>/example1</context-root>



              example1ejb.jar


              hibernateclasses.jar



              hibernate2.jar



              cglib-2.0-rc2.jar



              commons-logging.jar



              commons-collections.jar




              dom4j-1.4.jar



              odmg-3.0.jar



              ehcache-0.6.jar


              • 4. Re: Configuring Hibernate service
                joydeep

                Thanks for the pointer Touby, its resolved now. I did have another copy of hibernate2.jar in my war file. It worked after I removed it.... :-)

                • 5. Re: Configuring Hibernate service
                  ldecaro

                  Thanks for your reply, actually, it pointed me the way to solve my problem..

                  Just for the record I had the same error as you mate (same stack). In this particular case the app wasn't using Hibernate as a jboss service.
                  And the resolution was different.
                  I spent a long time trying to figure what was going wrong when i found in the middle of app's legacy jars a jta.jar that was causing the problem.
                  This jar was placed in the app's context (/lib). A simple shift+del solved it.
                  ;-)

                  Cheers,

                  :Luiz.