Reputation: 4591
I'm working with a Java program running on a Tomcat App server that is connected to a Teradata database that utilizes a UserTransaction
& session-factory
set in a hibernate configuration which connects to a datasource
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="connection.datasource">java:comp/env/My_DB</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
....
And a method to get the Transaction Context
public UserTransaction getTransactionContext()
throws Exception
{
if (this.ut == null) {
ut = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
}
return ut;
}
However, InitialContext
fails at lookup("java:comp/UserTransaction");
and returning:
03:27:37,530 ERROR [someServlet:555] Error in someMethod
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:117)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
I'm very new with using jta.UserTransaction
; the datasource mapping works as it should however I can't seem to get the UserTransaction returned - the naming convention itself matches between the code and session factory. Could anyone provide some possibilities on why this is failing from a high (or low) level perspective? I can provide additional info if this is too vague a question.
Upvotes: 1
Views: 1475
Reputation: 154070
Tomcat is a web server not a JTA compliant application server (e.g. JBoss, WebLogic, Glassfish).
If you want to use JTA you need to use a JTA stand-along implementation, like:
Embedding a standalone transaction manager will give you access to a JTA transaction manager exposing UserTransactions through JNDI.
Upvotes: 2