• Post Reply Bookmark Topic Watch Topic
  • New Topic

User Transaction  RSS feed

 
sapna rana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to implement user transaction in my application.
I am using JTA but my application does not include any bean.

Please suggest how can we integrate UT without EJB..
My code include
*******
public class VinFKSConnection {

final static String driverClass = "com.mysql.jdbc.Driver";
final static String connectionURL = "jdbc:mysql://172.16.80.214:3306/fkspocdb";
final static String userID = "root";
final static String userPassword = "root";
static UserTransaction utx = null ;
private static DataSource ds = null;



public static Connection getConnection() throws IOException
{
Connection conn =null;
try {

InitialContext ctx = null;
try {
ctx = new InitialContext();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Object txObj =ctx.lookup("java:comp/UserTransaction");


utx = (UserTransaction) txObj;
utx.begin();

System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "\n");
conn = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n");

*********

But i get following error

********


java.lang.ClassCastException: org.jboss.tm.usertx.client.ServerVMClientUserTransaction

at line utx = (UserTransaction) txObj;

********
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags
And, you cannot cast an Object to a UserTransaction class.
 
sapna rana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in that case how can we implement User transaction.
Please provide some sample if possible
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Prateek Parekh:
And, you cannot cast an Object to a UserTransaction class.[/QB]

Why not?

org.jboss.tm.usertx.client.ServerVMClientUserTransaction implements javax.transaction.UserTransaction so you should be able to case from one to the other. The same classes loaded by different classloaders can throw ClassCastExceptions. I'd have a look at what's in your classpath for both applications.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!