There are methods on the bean context
to control the transaction.
public boolean getRollbackOnly() ;
public void setRollbackOnly();
Thanks for your answer, but this is not exactly what I wanted to know...
I do not want to CHANGE the status, only GET it.
What is wrong with getRollbackOnly() ?
You can use the TransactionManger bound at
"java:/TransactionManager" to access the transaction.
> What is wrong with getRollbackOnly() ?
It only returns if the transaction is going to be rolled back or not.
But there are several other status, like "active" or "prepared". But in the j2ee-API-Documentation I found, that the method "getUserTransaction()" is available for SessionContext-objects. So I try this one first...
I think I would get the same object if I get the Transaction via TransactionManager, is this correct?
UserTranscations are for BMT (bean managed transactions).
The other statuses don't apply inside the bean
for CMT. You are either active or marked rollback.
The other statuses apply at the end of the work
when the container is committing/rolling back the
So the getUserTransaction() only returns an object, if I invoked the bean from within a bean-managed transaction? And if I control the transaction with a servlet?
And with container-managed transaction getUserTransaction returns null?
hmm... perhaps I should try it...
By the way:
I wonder what happens to transactions if they get suspended (e.g. when a method in a transaction invokes another method which is set to RequiresNew)
The getUserTransaction() method
creates a UT when one is not already assigned
to the bean.
For CMT it throws an exception.
For BMT any previous transaction is suspended.
If you invoke a RequiresNew method your
transaction is suspended, but it is activated again
by the time it returns to your method.
So the suspension is invisible to you.
I know that it isn't my business how a transaction gets suspended and how it is activated again. But I would really like to know (only the essence of it - no details, of course).
Remember my statement about the documentation?
Maybe you're glad to here, that I begun writing a tutorial about transactions, yesterday... (in German).
I'm reading and testing all the time. I'll put it on the web when it's finished...
Thanks for your help!