-
1. Re: How to retrieve the transaction Id ?
marklittle Oct 14, 2008 10:11 AM (in response to freejohn22)There is no standard way defined to obtain a transaction id (toString() is probably the best you'll get, but even then it'll depend on the underlying implementation). There are implementation specific avenues though.
-
2. Re: How to retrieve the transaction Id ?
freejohn22 Oct 14, 2008 11:01 AM (in response to freejohn22)Hello Mark,
thank you for your answer: yes I think toString could be sufficient anyway how can I get a reference to the Transaction when I'm inside an EJB CMT ? (with a BMT I could do a toString of UserTransaction but with CMT ? )
Thanks again -
3. Re: How to retrieve the transaction Id ?
mmusgrov Oct 14, 2008 1:29 PM (in response to freejohn22)A non portable way to get the current transaction when using the JBossTS manager is:
com.arjuna.ats.jta.TransactionManager.transactionManager().getTransaction();
All other TM products I've come across have similar mechanisms to get at the current transaction. -
4. Re: How to retrieve the transaction Id ?
marklittle Oct 15, 2008 2:51 AM (in response to freejohn22)But be aware that this is obviously non-portable across vendors. Not a lot we can do about that, I'm afraid.
-
5. Re: How to retrieve the transaction Id ?
dbush21 Dec 18, 2008 6:00 PM (in response to freejohn22)I believe that calling getTransaction() within JTA causes an illegal state exception ...
-
6. Re: How to retrieve the transaction Id ?
jhalliday Dec 19, 2008 4:47 AM (in response to freejohn22)> I believe that calling getTransaction() within JTA causes an illegal state exception ...
I believe you have not shown a stack trace that proves it. Save the belief for Santa Claus and stick to empirical evidence in the day job please.
Trying to access certain methods on UserTransaction during a container managed tx in EJB will be disallowed by the container, per the EJB (not JTA) spec. Use of the code snippet above won't. -
7. Re: How to retrieve the transaction Id ?
thomas.scheibelreiter Nov 27, 2018 6:39 AM (in response to freejohn22).toString() shows you a hex representation of UserTransaction.hashcode(). This is not the actual transaction ID. I observed, that CDI always injects the same UserTransaction object, but the underlying DB transaction changes.
-
8. Re: How to retrieve the transaction Id ?
ochaloup Nov 27, 2018 7:40 AM (in response to thomas.scheibelreiter)what do you mean by the hex representation, what do you get on that call? I expect the `toString()` method should be based by the call to narayana/BasicAction.java · GitHub which prints the transaction uid. Which is the actual transaction ID.
The CDI injection lifecycle is independent to transaction manager. I expect the CDI can reuse the same UserTransaction instance. The Narayana transaction context is hold as the thread local variable. The instance could be same but context depends what's saved at the thread.
Ondra
-
9. Re: How to retrieve the transaction Id ?
tomjenkinson Nov 27, 2018 8:49 AM (in response to ochaloup)ochaloup do you think that WFTC might not be printing the hex code? I wonder if this would help: Issue Navigator - JBoss Issue Tracker
In the meantime maybe if WFTC is wrapping Narayana here something could be done to unravel it in reflection or use Mikes snippet (com.arjuna.ats.jta.TransactionManager.transactionManager().getTransaction();)
-
10. Re: How to retrieve the transaction Id ?
ochaloup Nov 27, 2018 8:52 AM (in response to tomjenkinson)tomjenkinson yes, you are right. Thanks. I depends on the context. I just thought we talk about EJB JTA transaction as this thread started so.