• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

doubt on mock question

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UserTransaction ut = validContext.getUserTransaction();
The following code is given

ut.begin();
//some more valid code
...
ut.setRollbackOnly();
//some more valid code
...
ut.commit();

a The bean might be a Message Driven Bean.

b The bean must not be a stateful session bean.

c This must not be a stateless session bean.

d This code will throw an exception at runtime.


e This code will not compile.


f The bean must be an entity bean with bean managed persistence.


g Upon execution of this code, the container ensures that the transaction is not committed.

Answers are a and g

I don't understand why g? I think a and d.

bhilla
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bhilla,

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.

Thanks,
Prashant
 
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello bhila,


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.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

http://e-docs.bea.com/wls/docs81/javadocs/weblogic/transaction/AppSetRollbackOnlyException.html

Hope it helps.
 
Ådne Brunborg
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it helps, thanks, but - this exception is vendor-specific. So, is it the code which throws the exception, or is it the container?

[trying hard to understand exactly what happens here]
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I think the code is definitely BMT but need not be MDB. It can be any of the session beans. Correct me if i am wrong. i agrre on initial answers a and g to be correct.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that the code can be found in any type of bean except entity bean, which must be CMT.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rollback can also be achieved by UserTransaction.setRollbackOnly.
 
reply
    Bookmark Topic Watch Topic
  • New Topic