Atomikos Forum |
|
Hi,
I've configured a Hibernate Session Factory (org.springframework.orm.hibernate3.LocalSessionFactoryBean) to use Atomikos but I get an NPE: Everything works fine, until I switch to Atomikos's transaction factory, which gives me an NPE. This works fine: <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="atomikosDataSourceBean" /> <property name="mappingLocations"> <list> <value>classpath*:/hibernate/*.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop> </props> </property> </bean> When I switch to this: <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="atomikosDataSourceBean" /> <property name="mappingLocations"> <list> <value>classpath*:/hibernate/*.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory</prop> <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop> </props> </property> </bean> I get the NPE: No properties path set - looking for transactions.properties in classpath... transactions.properties not found - looking for jta.properties in classpath... Failed to open transactions properties file - using default values Exception in thread "main" java.lang.NullPointerException at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60) at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:57) at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:197) at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1315) at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:78) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544) at hibernate.ActionDAOHibernate.saveAction(ActionDAOHibernate.java:38)
After investigation,
I think it's got to do with the fact that Hibernate expects to find a transaction bound to the current thread. Now, considered that I will use this hibernate session factory to access a database inside a listener invoked by a Spring transacted DefaultMessageListenerContainer that receives JMS messages, I won't be able to issue beginTransaction(). What's the correct current_session_context_class then?
Ok thanks, I got DefaultMessageListenerContainer to work, but Hibernate is still not working.
I tried this: <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.connection.isolation">3</prop> <prop key="hibernate.current_session_context_class">jta</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop> <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop> </props> </property> and I get: Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: Could not find UserTransaction in JNDI: ; nested exception is org.hibernate.TransactionException: Could not find UserTransaction in JNDI: Didn't TransactionManagerLookup avoid JNDI?
I've got it to work:
<property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.current_session_context_class">jta</prop> <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop> </props> </property> But I cannot get Atomikos to commit my changes. After this code I see nothing in the database: UserTransaction ut = (UserTransaction) aC.getBean("AtomikosUserTransaction"); ut.begin(); sessionFactory.getCurrentSession().saveOrUpdate(action); ut.commit();
On the other hand, this works:
ut.begin(); Transaction transaction = sessionFactory.getCurrentSession().beginTransaction(); sessionFactory.getCurrentSession().saveOrUpdate(action); ut.commit(); transaction.commit(); It seems to me that com.atomikos.jdbc.AtomikosDataSourceBean is somehow not keeping track of transactions it provides. Could somebody give a hand? We're stuck. |