Atomikos Forum

Hibernate/Spring config

I'm using your Hibernate/Spring integration config example from
http://www.atomikos.com/Documentation/HibernateIntegration

I'm using an AS400 database, not Oracle, but have set up the config accordingly; Hibernate binds to the db and builds the SessionFactory. The problem comes when I try beginTransaction() on a Hib session; it blows up with the stack trace below; it is still  looking for JNDI.

I assume you've used this config in an example? Is there something that still needs to be set to tell Hib or Atomikos not to use JNDI? This is with TransactionsEssentials. Thanks.

SEVERE: Could not find UserTransaction in JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:342)
        at javax.naming.InitialContext.lookup(InitialContext.java:409)
        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:193)
        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 com.kve.vanguard.main.Main.main(Main.java:39)
Exception in thread "main" org.hibernate.TransactionException: Could not find UserTransaction in JNDI:
        at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:64)
        at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:57)
        at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:193)
        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 com.kve.vanguard.main.Main.main(Main.java:39)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:342)
        at javax.naming.InitialContext.lookup(InitialContext.java:409)
        at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60)
        ... 6 more
Harry Clark Send private email
Friday, May 28, 2010
 
 
Did you try with the latest 3.6.5?

Best
Guy Pardon Send private email
Friday, May 28, 2010
 
 
This is 3.6.5
Harry Clark Send private email
Friday, May 28, 2010
 
 
Here is the config:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd">
 
<beans> 
 
  <bean id="vanguardDataSource"
      class="com.atomikos.jdbc.AtomikosDataSourceBean"
      init-method="init" destroy-method="close">
      <property name="uniqueResourceName"><value>VANGUARDDB</value></property> 
      <property name="xaDataSourceClassName">
        <value>com.ibm.as400.access.AS400JDBCXADataSource</value>
      </property>
      <property name="xaProperties">
        <props>
          <prop key="serverName">192.168.1.22</prop>
          <prop key="user">clarkh</prop>
          <prop key="password">curlew01</prop>
        </props>
      </property>   
      <property name="poolSize" value="3"/>
  </bean>   

  <bean id="vanguardSessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="packagesToScan" value="com.kve.vanguard.model.orm.domain" />   
    <property name="dataSource" ref="vanguardDataSource" />
    <property name="configLocation">
      <value>classpath:hibernate.cfg.xml</value>
    </property>
    <property  name="configurationClass">
      <value>org.hibernate.cfg.AnnotationConfiguration</value>
    </property>
    <property name="hibernateProperties">
      <props>
        <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>       
        <prop key="hibernate.current_session_context_class">thread</prop>
        <prop key="hibernate.dialect">com.kve.vanguard.model.orm.util.KVESQLDialect</prop>           
        <prop key="hibernate.show_sql">false</prop>
        <prop key="hibernate.cache.use_second_level_cache">false</prop>
      </props>
    </property>
  </bean>    
 
  <bean id="hibernateTemplate" 
    class="org.springframework.orm.hibernate3.HibernateTemplate">
      <property name="sessionFactory"><ref bean="vanguardSessionFactory"/></property>
  </bean>

  <bean id="locationDao" class="com.kve.vanguard.model.orm.dao.GenericDaoImpl">
    <constructor-arg>
      <value>com.kve.vanguard.model.orm.domain.Location</value>
    </constructor-arg>
    <constructor-arg>
      <value>java.lang.String</value>
    </constructor-arg>
    <property name="sessionFactory">
      <ref bean="vanguardSessionFactory"/>
    </property>
  </bean>
   
</beans>
Harry Clark Send private email
Friday, May 28, 2010
 
 
I left one property out of the xaProperties,

<prop key="databaseName">KA2EJQDB</prop>

but it must have been supplied by my user profile on the AS400, because Hibernate bound to the datbase. The xaProperties given allow construction of the JDBC URL, which is not a property on the data source.

Stumped...
Harry Clark Send private email
Saturday, May 29, 2010
 
 
Not sure what you are doing, but the Hibernate properties should be set on the Hibernate template, which does not seem to be the case here...

HTH
Guy Pardon Send private email
Saturday, May 29, 2010
 
 
Without the hibernate properties on the SessionFactory it blows up earlier, with Hib errors.

Looking a bit more at the forum, is this problem  an outstanding bug?  An earlier post, "AtomikosJTATransactionFactory doesn't work without JNDI," refers to a case #32252, which I cannot find.

I got a little farther than before with the following jta.properties; stack trace follows; it doesn't like the fake for the setting it complained about earlier. It looks like the problem described in the earlier post; I haven't looked at the source.

java.naming.factory.initial=
com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.automatic_resource_registration=true
com.atomikos.icatch.console_log_level=DEBUG

Using init file: /C:/A_Vanguard/VanguardBase/bin/jta.properties
Exception in thread "main" org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager
    at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:181)
    at org.hibernate.jdbc.JDBCContext.<init>(JDBCContext.java:76)
    at org.hibernate.impl.SessionImpl.<init>(SessionImpl.java:213)
    at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:527)
    at org.hibernate.context.ThreadLocalSessionContext.buildOrObtainSession(ThreadLocalSessionContext.java:110)
    at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:76)
    at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
    at com.kve.vanguard.main.Main.main(Main.java:39)
Caused by: com.atomikos.icatch.SysException: Error in init of UserTransactionServiceImp: com.atomikos.icatch.standalone.UserTransactionServiceFactory
    at com.atomikos.icatch.config.UserTransactionServiceImp.checkInit(UserTransactionServiceImp.java:334)
    at com.atomikos.icatch.config.UserTransactionServiceImp.createTSInitInfo(UserTransactionServiceImp.java:346)
    at com.atomikos.icatch.jta.UserTransactionManager.checkSetup(UserTransactionManager.java:62)
    at com.atomikos.icatch.jta.UserTransactionManager.getStatus(UserTransactionManager.java:157)
    at org.hibernate.transaction.JTATransactionFactory.isTransactionInProgress(JTATransactionFactory.java:94)
    at org.hibernate.jdbc.JDBCContext.isTransactionInProgress(JDBCContext.java:187)
    at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:159)
    ... 7 more
Harry Clark Send private email
Saturday, May 29, 2010
 
 
I am not sure yet about what exactly this is. The bug you refer to has been fixed in is in the 3.6.5 release too, so that should not be it...
Guy Pardon Send private email
Monday, May 31, 2010
 
 
Which Hibernate did you test with? This example uses the Red Hat-supported Hibernate, not the public open source. There are differences, not sure exactly what, though the source is also provided. This is with

Hibernate
version 3.2.4.sp1.cp03, May 2, 2008

and

JBoss Seam FP
version 2.0.2-FP, May 2008

We are not running JBoss or Seam, but you have to put together a full Hibernate distro from these sources. Our annotations comes from the Seam FP library. This is Red Hat's procedure, not our invention.

There may well be differences with the public open source.
Harry Clark Send private email
Tuesday, June 01, 2010
 
 
That's not the problem. I changed the jars in the build path to use the public Hibernate and got the same problem.
Harry Clark Send private email
Tuesday, June 01, 2010
 
 
hello harry,

i don't know what causes the JNDI error, but i think this is a configuration problem. i will compare your spring configuration with my setup later this day. i use spring and hibernate too, but with a PostgreSQL database.

why are you using atomikos? do you need XA transactions? if yes, you need to change the hibernate property "hibernate.current_session_context_class" to "jta".

hth,
tscho
Tscho T Send private email
Tuesday, June 01, 2010
 
 
Did you read:

http://www.atomikos.com/Documentation/HibernateIntegration#With_JPA

If your Hibernate Version is "up-to-date" your configuration will fail.
Torsten Krah Send private email
Tuesday, June 01, 2010
 
 
Thanks Tscho. I'd like to believe it's a config problem. But changing "thread" to "jta" for current session context class did not help. Still getting the exception below, can't find a transaction. The jta.properties is

com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.automatic_resource_registration=true
com.atomikos.icatch.console_log_level=DEBUG

Yes I need JTA, not for a single data source obviously, but I'm just getting started.

Torsten, I don't follow you. I'm not using JPA but Hibernate (SessionFactory, not EntityManager)

Using init file: /C:/A_Vanguard/VanguardBase/bin/jta.properties
Exception in thread "main" org.hibernate.HibernateException: Problem locating/validating JTA transaction
    at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:74)
    at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
    at com.kve.vanguard.main.Main.main(Main.java:39)
Caused by: com.atomikos.icatch.SysException: Error in init of UserTransactionServiceImp: com.atomikos.icatch.standalone.UserTransactionServiceFactory
    at com.atomikos.icatch.config.UserTransactionServiceImp.checkInit(UserTransactionServiceImp.java:334)
    at com.atomikos.icatch.config.UserTransactionServiceImp.createTSInitInfo(UserTransactionServiceImp.java:346)
    at com.atomikos.icatch.jta.UserTransactionManager.checkSetup(UserTransactionManager.java:62)
    at com.atomikos.icatch.jta.UserTransactionManager.getTransaction(UserTransactionManager.java:166)
    at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:59)
    ... 2 more
Harry Clark Send private email
Tuesday, June 01, 2010
 
 
This is starting to work. When current_session_context_class is "jta", you have to use openSession(), not getCurrentSession(), on the SessFact. When you getCurrent, it looks for an existing tx, and throws if one is not found. Once you have a Session, then sess.getTransaction() and tx.begin().

My current problem is with the AS400XADataSource which I've configured, bean below. The properties shown result in the user (clarkh) being used as the databaseName. The exception stack trace contains:

Caused by: java.sql.SQLException: [SQL0204] DBAPREP in CLARKH type *FILE not found.

DBAPREP is in KA2EJQDB, which is apparently being ignored somewhere. I can't see how to config the JDBC URL directly on the XADataSource. Is there another way in the Atomikos config? Thanks.

<bean id="vanguardDataSource"
class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName"><value>VANGUARDDB</value></property>
<property name="xaDataSourceClassName">
<value>com.ibm.as400.access.AS400JDBCXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="serverName">192.168.1.22</prop>
<prop key="databaseName">KA2EJQDB</prop>
<prop key="user">clarkh</prop>
<prop key="password">curlew01</prop>
</props>
</property>
<property name="poolSize" value="3"/>
</bean>
Harry Clark Send private email
Friday, June 04, 2010
 
 
I am finally connecting to my database, found another property on the XADataSource class to point to the right database. So I am off and walking with Atomikos.
Harry Clark Send private email
Friday, June 04, 2010
 
 
Hi,

Thanks for the feedback and sorry for not being able to help more. Feel free to update our doc/wiki if you have time, so other users can avoid the same pains: http://www.atomikos.com/Documentation

Thanks,
Best
Guy Pardon Send private email
Tuesday, June 08, 2010
 
 

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

Other recent topics Other recent topics