1 Reply Latest reply on Aug 24, 2005 4:57 AM by kalvinklein

    org.jboss.tm.TxManager, JBoss3 vs. JBoss4, ClassCastExceptio

    kalvinklein

      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?