Standalone JBossTS with Hibernate Shards
david.pellegrini Feb 2, 2009 12:51 PMHi,
I'm trying to get JBossTS working in a standalone setup. The application will eventually run in JBossAS, but right now I need to get it running in a JUnit test environment (hence the standalone requirement).
The app has been working using the Hibernate Transaction API, and I am trying to get it working against the JTA API as recommended in "Java Persistence with Hibernate" and other references. Given the tight relationship between Hibernate and JBoss, I elected to integrate with JBossTS, especially since it can run standalone.
According to the examples, I just have to add the following to my Hibernate configuration:
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property> <property name="transaction.factory.class">org.hibernate.transaction.JTATransactionFactory</property>
The examples also make reference to a datasource. To complicate matters, my database is sharded using Hibernate shards. I have not set up my database shards as "datasources" but instead configured via distinct cfg.xml files (which works fine until I throw JBossTS into the mix). How important is it to have my shards set up and referenced as datasources?
In any event, when I run, the SessionFactories for the shards are created as expected, but then it can't find the TransactionManager. Here's an excerpt from the log file:
2009-02-01 12:29:08,537 INFO [main] util.NamingHelper(49): JNDI InitialContext properties:{java.naming.provider.url=file:/opt/jndi, java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory} 2009-02-01 12:29:08,564 INFO [main] impl.SessionFactoryObjectFactory(114): Bound factory to JNDI name: HibernateSessionFactory0 2009-02-01 12:29:08,565 WARN [main] impl.SessionFactoryObjectFactory(124): InitialContext did not implement EventContext 2009-02-01 12:29:08,565 INFO [main] util.NamingHelper(49): JNDI InitialContext properties:{java.naming.provider.url=file:/opt/jndi, java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory} 2009-02-01 12:29:08,567 ERROR [main] session.HibernateUtil(84): Initial SessionFactory creation failed. org.hibernate.HibernateException: Could not locate TransactionManager at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:60) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:357) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327) at org.hibernate.shards.ShardedConfiguration.buildSessionFactory(ShardedConfiguration.java:251) at org.hibernate.shards.ShardedConfiguration.buildShardedSessionFactory(ShardedConfiguration.java:177) at com.spokesoftware.spokebook.hibernate.session.HibernateUtil.<clinit>(HibernateUtil.java:76)
It seems that Hibernate is trying to lookup the TransactionManager via JNDI at the location specified by JBossTransactionManagerLookup, but no TransactionManager has been created and left there. So, what more do I need to do to wire in the JBossTS? BTW, the JBossTS jars and their dependent lib dirs are all in the classpath.
Looking for the missing link ...
Thanks!