I hope that what I am about to ask isn't too vague. I inherited a piece code that I am trying to debug. In this particular chunk, I have a session bean that wraps an entity bean. The entity bean has bean managed persistence, and behaves normally 99% of the time. In some cases I can see it fail, but I am having a hard time making the mental connection on how a bean transitions to its ejbLoad method. I am using BEA Weblogic 5.1 with service pack 6. I guess what it comes down to, is there anyone out there who has seen a similar design and can you offer any debugging tips. I appreciate everyones time who had a chance to read this. Thanks, Eric
I'm not sure if this helps at all, but: ejbLoad is called by the container in two cases that I can think of.
If you business method is transactional, then it will call ejbLoad immediately before the transaction starts. (when you call MyMethod from the remote interface, the container will call ejbLoad before calling the corresponding MyMethod in the EJB)
Also, the container will call ejbLoad immediately after activating a passivated EJB. ie: when a bean is moved from the pooled to the ready state, the container calls ejbActivate, followed by ejbLoad.
Mike- I appreciate your quick reply. I have a couple of additional questions. 1) Is a business method considered transactional if it hits the database? In my case I am trying to retrieve instance data and I can see that before my method is called my ejbLoad code fires. So I'm guessing that this is true. 2) Within the bean, right before I call the 'transactional method', the member variables of the bean have expected values. Then right before ejbLoad is invoked, it will sometimes revert back to the previous state and work with the wrong values. I know it is probably not advisable, but is it possible to make the container call the ejbStore method ( or I can do it myself ) when I know the state of the bean is correct? I'm still trying to track down where it might be failing, all of my ejb key lookups work, etc... The worst part is that this is fairly intermittent, so I'm really just trying to force a workaround at this point. Again, thanks so much for your help. - Eric
1) Is a business method considered transactional if it hits the database? In my case I am trying to retrieve instance data and I can see that before my method is called my ejbLoad code fires. So I'm guessing that this is true.
Most probably, you would have set the business method in the transactional state.This could be the reason, ejbLoad() gets fired before your business method.The Entity Bean instance variables are loaded from the DB in the "transactional type", you specify.
2) Within the bean, right before I call the 'transactional method', the member variables of the bean have expected values. Then right before ejbLoad is invoked, it will sometimes revert back to the previous state and work with the wrong values. I know it is probably not advisable, but is it possible to make the container call the ejbStore method ( or I can do it myself ) when I know the state of the bean is correct?
It is best to design your application considering that ejbLoad() would be called before your business method.ejbLoad() would load the data available in the DB, and you can then re-initialize it in the business method to the values you want.The Container recognizes the change in state of the instance variables and synchronizes the data by calling ejbStore(). Note that your EJB Container is designed to manage ejbLoad()/ejbStore() - The Bean Developer shouldn't be concerned about it. Hope this helps. Regards, Sandeep
Sun Certified Programmer for Java 2 PlatformScored 93 per cent
Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
IBM Enterprise Connectivity with J2EE Scored 72 per cent
Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
[This message has been edited by Desai Sandeep (edited May 10, 2001).]
Sandeep- Thanks for your reply. Both you and Mike have helped me a lot. Right now I am going to spend some time to find out what the real root of my problem is. If I find it, or have more questions, I'll post to this thread. Given what you and Mike have taught me, the first instantiation of the entity bean through the session bean always works. Then sometimes, a subsequent call to the enitity bean will return the original values. To understand this a bit more, the session bean is used to pick a business category, and then the entity bean refers to instances of the particular category. When I notice a failure its because the data returned by the bean is always for the previous session bean. Again, this was inherited code, and with the help I've gotten here I am certainly ahead of the curve now. I suspect its a client issue, not properly changing state or something like that. Thanks so much for you help and patience! - Eric
Could you hold this kitten for a sec? I need to adjust this tiny ad: