Why do u think answer is d? When u execute ut.setRollbackOnly(), the transaction is marked for rollback. And, after executing commit(), the container sees that this transaction is marked for rollback, so will not commit it.
g)Upon execution of this code, the container ensures that the transaction is not committed
If the transaction is already marked for rollback then container will make sure that it will never commit. This makes the option g correct.
d This code will throw an exception at runtime.
This is also correct. Most of the container will throw error in this case. But then it again depends upon the container implementation. In case of weblogic "AppSetRollbackOnlyException" will be thrown. I am not very sure that what specs say about this but I believe that its upto the container provider.
Hope it helps.
Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
This is also correct. Most of the container will throw error in this case. But then it again depends upon the container implementation.
I don't see why this code would throw an exception, please enlighten me... [ August 12, 2005: Message edited by: �dne Brunborg ]
Entia non sunt multiplicanda praeter necessitatem
Joined: Aug 24, 2004
I don't see why this code would throw an exception, please enlighten me...
The exception will be thrown because we are trying to commit a transaction that is alreday marked for rollback. It will be helpful if for example we consider weblogic. It throws AppSetRollbackOnlyException to indicate that a transaction was marked for rollback by an application component.
The container may throw an exception, so d is incorrect.
Note that if weblogic.transaction.AppSetRollbackOnlyException were thrown (upon invocation of ut.commit()), then this exception should be handled by logging it for a message-driven bean. It would not make sense for a checked exception like this to be thrown from an MDB as there is no client.
This is the process of thinking out aloud and please tell me if the following explanation in support for the original answers are correct.
1. This code might be MDB. 2. if it is MDB, it is Bean Managed. 3. So call to setRollbackOnly() itself will throw an exception IllegalStateException but in case of MDB, it will be logged. 4. And since the exception is System exception, it would prevent the method from successfully completing. Spec page 377. And thus container will ensure that rollback occurs. [ August 14, 2005: Message edited by: seemapanth Joshi ]
option d should also be correct, if doesn't throw the exception then how will it know about the rollback!, when the transaction is rolledback , should throw the exception , to inform that the transaction has been rolledback! when one say's the code throws exception at runtime, it's logical to assume that the container throws the exception to code and code throws the same!
Joined: Sep 29, 2002
Rollback can also be achieved by UserTransaction.setRollbackOnly.