-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JOTM + Hibernate error
PostPosted: Tue Jul 25, 2006 3:05 am 
Newbie

Joined: Fri Jul 21, 2006 6:48 am
Posts: 2
Hi

I am trying to use JOTM with hibernate, I am able to get session factory and session objects inside my code but I am geeting:

ERROR: org.hibernate.TransactionException: Unable to locate UserTrasnaction to check status


Please suggest,

I am including the code:

Thanks
Mohit
=================================
package foo;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.transaction.UserTransaction;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class DBTest{

int foo = -1;
static UserTransaction ut;
Session session = null;

static {
try {
Context ctx = new InitialContext();
ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction");
}catch(Exception e) {
System.out.print("DBTest >> ");
e.printStackTrace();
}
}

public void init(String completion) {
try{

System.out.println("<<< beginning the transaction + session factory created>>>");


System.out.println("foo = "+ foo +" (before completion)");



if (completion != null && completion.equals("commit")) {
ut.begin();
SessionFactory sFBase = new Configuration().
configure("hibernate_foo.cfg.xml").buildSessionFactory();

System.out.println("<<< starting committing the transaction >>>");

session = sFBase.openSession();

System.out.println("before Inserting Record for javatest");

foo.hibernate.com.infosys.Testdata ts = new foo.hibernate.com.infosys.Testdata();
ts.setFoo(new Integer(6));
ts.setId(2);

session.save(ts);

System.out.println("Done updating JavaTest");


ut.commit();
} else {
System.out.println("<<< rolling back the transaction >>>");
//ut.rollback();
}
System.out.println("foo = "+ foo +" (after completion)");

System.out.println("<<< done >>>");
}catch(Exception e) {
System.out.print("DBTest >> ");
e.printStackTrace();
}
}

public String getFoo() { return ""+foo; }
}

==========================================
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/myDB</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JOTMTransactionManagerLookup</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="foo/hibernate/com/infosys/Testdata.hbm.xml" />
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.