• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Bean stuff in ejbCreate of stateful session bean

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some doubts that could be in the 'ejbCreate' method
of Stateful session beans.

HFEJB mentions that
'setting rollbackonly' and getting the status of rollback(CMT) cannot be done in ejbCreate (thro' SessionContext) whereas these operations could be performed using 'UserTransactions' in BMT.

What is the reason behind this?

Thanks for the help!!
Muthu
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a little confused about this too. Looks like with CMT the stateful bean's ejbCreate() is run in an unknown tx context and so you cannot do a rollback. There is no container transaction to rollback.

However, with BMT during ejbCreate() you can lookup your own UserTransaction(you would usually not do this, but since there is a client associated you have the option of creating a tx) and hence call rollback on the tx you created.
Not sure this helps, anyone with a better explanation??
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the Ejb 2.0 Spec (Page 76 Section 7.5.7)Transaction Context of session bean methods:

A session beans newInstance(),setSessionContext(),ejbCreate(),ejbActivate() ejbPassivate() and ejbRemove() are called in an unspecified transaction context since there is no transaction you cannot set it to roll back
setRollbackOnly() and also neither you can check whether it has been set to roll back only getRollbackOnly()
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Muthu,

Thanks for posting a good question.


HFEJB mentions that
'setting rollbackonly' and getting the status of rollback(CMT) cannot be done in ejbCreate (thro' SessionContext) whereas these operations could be performed using 'UserTransactions' in BMT.



You can call the getUserTransaction() method in ejbCreate(), for both Stateful & Stateless session beans (BMT beans only). The return type of this method will be an object of type UserTransaction.

Only for Stateful session beans(BMT), in ejbCreate(), you can access UserTransaction methods, but not all the methods. UserTransaction methods are not avaible in session beans, since there is no client associated with the bean, during creation.

The Spec says (Pg- 81):

Additional restrictions:
The getRollbackOnly and setRollbackOnly methods of the SessionContext
interface should be used only in the session bean methods that execute in the context of a transaction.
The Container must throw the java.lang.IllegalStateException if the
methods are invoked while the instance is not associated with a transaction.



So it is confirmed that you cannot call setRollBackOnly() methods in ejbCreate(), irrelevant of whether the bean is stateful/stateless or CMT/BMT.

You can refer the tables in page 80 & 90 of the spec.
 
Charlie A
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just corrected the typo error of the previous blog


Only in Stateful session beans(BMT), in ejbCreate(), you can access UserTransaction methods, but not all the methods. UserTransaction methods are not avaible in stateless** session beans, since there is no client associated with the bean, during creation.

 
muthu kumaran
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone for the info.


Only in Stateful session beans(BMT), in ejbCreate(), you can access UserTransaction methods, but not all the methods.



Does the spec specify which methods can be accessed and which cannot?

Thanks,
 
Charlie A
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Does the spec specify which methods can be accessed and which cannot?


Yes, the Spec provide these details. Please refer the tables in Pg-80,90 of the spec.
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic