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.
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 ? )
A non portable way to get the current transaction when using the JBossTS manager is:
All other TM products I've come across have similar mechanisms to get at the current transaction.
But be aware that this is obviously non-portable across vendors. Not a lot we can do about that, I'm afraid.
I believe that calling getTransaction() within JTA causes an illegal state exception ...
> 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.