Atomikos Forum

NullPointerException w/Hibernate

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)
piero de salvia Send private email
Tuesday, June 02, 2009
 
 
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?
piero de salvia Send private email
Tuesday, June 02, 2009
 
 
Hi,

Try configuring the DefaultMessageListenerContainer for JTA instead, and make sure to set sessionTransacted=true

HTH
Guy Pardon Send private email
Tuesday, June 02, 2009
 
 
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?
piero de salvia Send private email
Tuesday, June 02, 2009
 
 
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();
piero de salvia Send private email
Tuesday, June 02, 2009
 
 
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.
piero de salvia Send private email
Tuesday, June 02, 2009
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics