Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB - Session Beans Question

 
Aleena Rehman
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a few questions ....
(1) Why we cannot either force a trasaction to rollback (CMT) or findout if a trasnaction has been set to rollback only in ejbCreate for stateful session beans ?
(2) Also if I can access my JNDI Environment in setSessionContext() why I cannot
- access another bean's methods ?
- access a resource manager (like database)

Thanking in advance

Regards
 
Greg Charles
Sheriff
Posts: 3002
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. The ejbCreate() method doesn't run in a valid transactional context. The spec doesn't do much to explain why not, except to say that it would unnecessarily complicate the life cycle of the stateful session bean. I'm willing to accept this explanation. Unlike an entity bean, which usually has to write an entry to a database as part of its create process, a stateful session bean just needs to populate its state variables. It might need to read data from a database, either directly or through other beans, but it would never need to alter any data during the creation process. If it doesn't alter data, then it doesn't need a transaction.

2. setSessionContext(), and all the other setXxxxContext() methods, are just part of the setup process for the bean. They can be used to store values and references to objects that will be used later, but shouldn't be used to do any real work. Usually they are just used to store a reference to the context in the bean instance for later use. However, you could also store a reference to the Home interface, or set up the values and object references configured in the bean's environment. You can't actually use these object references until later in the life cycle, but at least you can get them ready.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic