Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTA Problem--The Xid is not valid

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
I am writing a small application which i am posting at the end.This is decription of my application.I am writing a jsp.Later on i will be using in some other way.
I am using Oracle XA implementation to communicatewith my RM which oracle8.1.7 .
I am creating two XAConnection with two data instances 'test' and 'test3' .These two reside on my local machine in the same database server.
With the code which i am sending you i have tried two cases.
First Case
-----------
1)i use only one XAConnection object of say 'test'.
2)enlist its XADataSource with my transaction Object
3) get two connection objects and execute two sql's on themMy code works fine and maintains the transaction.

Second Case
------------
1) I use create two XAConnection objects. one of 'test' and other of 'test3'.
2) enlist their XAResources with transaction object.
3) Now i take one connection from each of XAConnection and execute two sqls, oneon each of them.
It gives me exception while enlisting second XAResource with transaction objeectsaying that "The Xid is not valid".
below is the stackTrace.
//////
javax.transaction.SystemException: start() failed on resource 'oracle.jdbc.xa.client.OracleXAResource':XAER_NOTA : The XID is not valid
oracle.jdbc.xa.OracleXAException at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:483)
at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:190)
at weblogic.transaction.internal.ServerResourceInfo.start(ServerResourceInfo.java:1165)
at weblogic.transaction.internal.ServerResourceInfo.xaStart(ServerResourceInfo.java:1108)
......
.....
...
//////

<----------------------CODE------------------------------------------------------>
<html>
<body bgcolor=tan>
<%@page session="true" %>
<%@page import="java.util.Hashtable,java.sql.*,javax.naming.*,javax.transaction.*,javax.sql.*,oracle.jdbc.xa.client.OracleXADataSource,javax.rmi.PortableRemoteObject,javax.transaction.xa.XAResource" %>
<%!
private static XAConnection getFirstXAConnection() throws java.sql.SQLException{
OracleXADataSource oxadsFirst = new OracleXADataSource();
String urlFirst = "jdbc racle:thin:@70.7.51.80:1521:test";
oxadsFirst.setURL(urlFirst);
XAConnection xaConnectionFirst = oxadsFirst.getXAConnection("scott","tiger");
return xaConnectionFirst;
}
private static XAConnection getSecondXAConnection() throws java.sql.SQLException{
OracleXADataSource oxadsSec= new OracleXADataSource();
String urlSec = "jdbc racle:thin:@70.7.51.80:1521:test3";
oxadsSec.setURL(urlSec);
XAConnection xaConnectionSec = oxadsSec.getXAConnection("scott","tiger");
return xaConnectionSec;
}
%>
<%
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
try{
ctx = new InitialContext(ht);
//javax.transaction.UserTransaction transaction = (javax.transaction.UserTransaction)ctx.lookup("java:comp/UserTransaction");
System.out.println("Before Lookup JNDI UserTransaction and TransactionManager......................");
//javax.transaction.UserTransaction userTx = (javax.transaction.UserTransaction)ctx.lookup("javax.transaction.UserTransaction");
javax.transaction.TransactionManager transactionManager = (javax.transaction.TransactionManager)ctx.lookup("javax.transaction.TransactionManager");
System.out.println("After Lookup TransactionManager......................");
try{
transactionManager.begin();
Transaction transaction = transactionManager.getTransaction();
System.out.println("Transaction Object ----------------------------->"+transaction);
XAConnection xaConFirst = getFirstXAConnection();
XAResource xaResourceFirst = xaConFirst.getXAResource();
System.out.println("xaResourceFirst Object ----------------------------->"+xaResourceFirst);
XAConnection xaConSecond = getSecondXAConnection();
XAResource xaResourceSecond = xaConSecond.getXAResource();
System.out.println("xaResourceSecond Object ----------------------------->"+xaResourceSecond);
if(!xaResourceFirst.isSameRM(xaResourceSecond) )
System.out.println("<-----------------BOTH THE RESOURCES ARE NOT SAME SMAE SAME----------------------------->");

boolean firstEnlistBool = transaction.enlistResource(xaResourceFirst);
System.out.println("firstEnlistBool ----------------------------->"+firstEnlistBool);
boolean secondEnlistBool = transaction.enlistResource(xaResourceSecond);
System.out.println("secondEnlistBool -------------------------> "+secondEnlistBool);
java.sql.Connection firstConn = xaConFirst.getConnection();
Statement stmt = firstConn.createStatement();
stmt.executeQuery("insert into dept values(60,'MARKETING','NEW DELHI')");
java.sql.Connection secondConn = xaConSecond.getConnection();//xaConFirst.getConnection();//
stmt = secondConn.createStatement();
//stmt.executeQuery("insert into account values(20,20)");
stmt.executeQuery("insert into salgrade values(10,10,10)");
if(Status.STATUS_ACTIVE == transactionManager.getStatus() )
System.out.println("Before committing status "+transactionManager.getStatus() );
transactionManager.commit();
System.out.println("After committing");
} catch(SQLException sqlE){
sqlE.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {
ctx.close();
}
catch (Exception e) {
e.printStackTrace();
}
} // close finally
%>
<form method="post">
<input type="submit" name="submit" value="Call Transaction Bean">
</form>
</html>
<-------------------------------------------------------------------------------->
please help in this..I am stuck with this and dont kow how to move ahead to remove this problem..
Best Regards
Akhil Nagpal
 
Beauty is in the eye of the tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic