Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When are ejbLoad and ejbStore called?

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using the J2EE (1.2.1) tutorial and I'm going to ask a question that has to do with the Account example. On page 48, it says
If a business method is associated with a transaction, the container invokes ejbLoad before the business method executes. Immediately after the business method executes, the container calls ejbStore. Because the container invokes ejbLoad and ejbStore, you do not have to refresh and store the instance variables in your business methods - the container performs these functions for you.
Further, for this particular tutorial, they specify that all methods 'require' transaction.

My question is this: What if a bean's instance variables are changed by a non-transactional method, and then no other transactional methods are called before ejbPassivate is called by the container? Will the changed data be lost? Or will the container call the ejbStore? (This is BMP also)

I'm not sure how to force passivation, so I can't test this out.
[This message has been edited by Mike Curwen (edited April 17, 2001).]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll answer this myself, for those interested:

Nowhere in the J2EE tutorial (1.2.1) does it mention this, but reading another book (Ed Roman's Mastering EJB), I discovered that ejbLoad is called immediately after ejbActivate when a bean is activated, and ejbStore is called immediately before ejbPassivate when a bean is to be passivated.

This is very satisfactory, and therefore does not require a transaction on every business method that could possibly change state information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic