JBoss 3.2.1 & Oracle 9i
I am using the following code to get an instance of my TransactionManager and then to obtain the status of my current transaction. I then plan to use the status to determine if I am already in a transaction (and therefore want to get the XA DataSource) or if I am not currently in an active transaction (and therefore want to get the non-XA DataSource). The problem is that the getStatus() method is ALWAYS returning Status.STATUS_ACTIVE.
txMgr = (TransactionManager)new InitialContext().lookup("java:/TransactionManager");
int txStatus = txMgr.getStatus();
if (txStatus == Status.STATUS_ACTIVE)
ds = (DataSource) ctx.lookup("java:/XA-DS");
else
ds = (DataSource) ctx.lookup("java:/NONXA-DS");
Like I mentioned above, the XA datasource is always returned, even when I'm not in a transaction. So of course I get exceptions a few steps later like this...
[TransactionImpl] XAException: tx=TransactionImpl:XidImpl [Fo
rmatId=257, GlobalId=SHASKINSLT//25, BranchQual=] errorCode=XAER_PROTO
and
[TransactionImpl] XAException: tx=TransactionImpl:XidImpl [Fo
rmatId=257, GlobalId=SHASKINSLT//25, BranchQual=] errorCode=XAER_PROTO
and
[TransactionImpl] XAException: tx=TransactionImpl:XidImpl [Fo
rmatId=257, GlobalId=SHASKINSLT//25, BranchQual=] errorCode=XAER_RMERR
Am I getting my TxMgr the wrong way? Is my approach fundamentally flawed? Any advice is greatly appreciated.