2 Replies Latest reply on Aug 24, 2005 5:00 AM by Mihai Onescu

    Spring, Hibernate and JBoss

    John Pount Newbie

      I have a small test application that uses Spring, Hibernate and connects to DB2.
      Everything works fine when using WSAD + WebSphere and I am having trouble getting the same thing going in JBoss.

      My two main problems are :

      1. Using JTA
      2. Configuring an XA datasource for DB2


      In my spring config file I am using the following transaction related details .....

      transactionManagerName = java:/TransactionManager



      If I use the hibernate transaction manager everything is ok, but if I use the JTA entry then I get the following error ...

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [testadmin-ctx.xml]: Initialization of bean failed; nested exception is org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:/TransactionManager]; nested exception is javax.naming.NamingException: Object [org.jboss.tm.TxManager@69cfe0] available at JNDI location [java:/TransactionManager] does not implement [javax.transaction.TransactionManager]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:341)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:222)

      If I look in the JBoss console I can see the TransactionManager in the java namespace under JNDI view so I guess it must be set up wrong or my spring config is wrong ...

      +- TransactionManager (class: org.jboss.tm.TxManager)

      XA Datasource

      I can setup and read from the database if I copy the db2-ds.xml file and change it for my database. However if I use the db2-xa-ds.xml then I cannot get a connection. I am using the following driver ...


      I've read through loads of posts and tried a number of configurations but still no joy. Can anyone help ?


        • 1. Re: Spring, Hibernate and JBoss
          Mihai Onescu Newbie

          We have almost the same problem, but no solution yet...

          Hi there,

          I have problems when deploying an application in JBoss 4. The application is using spring and hibernate. The logs look like this:

           [exec] 09:45:00,717 INFO [SettingsFactory] Default entity-mode: pojo
           [exec] 09:45:01,090 INFO [SessionFactoryImpl] building session factory
           [exec] 09:45:01,127 WARN [Configurator] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/nelu/tmp/1/target/app/app/tmp/deploy/tmp65501test.war/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
           [exec] 09:45:02,006 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
           [exec] 09:45:02,007 INFO [NamingHelper] JNDI InitialContext properties:{}
           [exec] 09:45:02,011 INFO [DefaultListableBeanFactory] Destroying singletons in factory {org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [hibernateInterceptor,sessionFactory,transactionManager,formatDaoImpl,formatServiceImplTarget,formatServiceImpl,/formats]; root of BeanFactory hierarchy}
           [exec] 09:45:02,012 ERROR [ContextLoaderPlugIn] Context initialization failed
           [exec] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.ClassCastException: null
           [exec] java.lang.ClassCastException
           [exec] at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:29)
           [exec] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:270)
           [exec] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
           [exec] at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:769)

          Here is the source code of the class JNDITransactionManagerLookup:

          28 try {
          29 return (TransactionManager) NamingHelper.getInitialContext(props).lookup( getName() );
          30 }

          I added some "debug code" to the class like this:

          22 try {
           23 // Debug
           24 System.out.println("getName() = " + getName());
           25 Object o = NamingHelper.getInitialContext(props).lookup( getName() );
           26 System.out.println("o.toString() = " + o.toString());
           27 System.out.println("o.getClass().getName() = " + o.getClass().getName());
           28 System.out.println("o instanceof TransactionManager = " + (o instanceof TransactionManager));
           29 TransactionManager tm = (TransactionManager) o;
           30 System.out.println("tm.toString() = " + tm.toString());
           31 System.out.println("tm.getClass().getName() = " + tm.getClass().getName());
           32 //
           33 return (TransactionManager) NamingHelper.getInitialContext(props).lookup( getName() );
           34 }
          And I am getting this output:

          [exec] 09:45:02,007 INFO [STDOUT] getName() = java:/TransactionManager
           [exec] 09:45:02,009 INFO [STDOUT] o.toString() = org.jboss.tm.TxManager@1cfd7c
           [exec] 09:45:02,009 INFO [STDOUT] o.getClass().getName() = org.jboss.tm.TxManager
           [exec] 09:45:02,010 INFO [STDOUT] o instanceof TransactionManager = false
           ... and the ClassCastException moves now to the line 29.

          In the documentation of JBoss4 it seems that the class org.jboss.tm.TxManager implements javax.transaction.TransactionManager and the code should work ok, but it doesn't!

          Are there any differences between JBoss3 and JBoss4 regarding the transactions? Any ideas on how to solve this problem?

          • 2. Re: Spring, Hibernate and JBoss
            Mihai Onescu Newbie

            This solution solves the "ClassCastException" problem.

            Look out for .jar files that contain the same packages. For example both jta.jar and jboss-j2ee.jar contain the package "javax.transaction.TransactionManager"