• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two more EJB Questions.

 
Prasad Kuppa
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone confirm whether the answers to the following questions are correct? I appreciate if you can explain how they are correct too..

When is ejbStore() invoked?
a. Immediately before the container reads the Bean's state information.
b. Immediately after the containter reads the BEan's state information

Correct answer given : A

When is ejbLoad() invoked?
a. Immediately before setting the Bean's state information.
b. Immediately after setting the Bean's state information

Correct answer given : B

Thanks,

Prasad
 
Goutam Bhattacharjee
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The qs is obviously meant for CMP, as in BMP, programmer must write the state synchronization himself/herself.
Watch the following cycle of events; u will get the answer.

For CMP
---------
Read bean's state from DB-->ejbLoad()-->Execute bean's business method(This will change the state)-->ejbStore()-->persist state in DB-->Read bean's state from DB-->ejbLoad()-->.........continue
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The qs is obviously meant for CMP, as in BMP, programmer must write the state synchronization himself/herself.


I'm not sure I'm with you on that, as http://java.sun.com/developer/onlineTraining/EJBIntro/EJBIntro.html says:

In BMP, the ejbLoad() and ejbStore() methods are invoked by the container to synchronize the bean instance with data in the database.


About the questions, the outstanding tutorial page says:



The ejbLoad() and ejbStore() methods in CMP entities are invoked when the entity bean's state is being synchronized with the database. The ejbLoad() is invoked just after the container has refreshed the bean container-managed fields with its state from the database. The ejbStore() method is invoked just before the container is about to write the bean container-managed fields to the database. These methods are used to modify data as its being synchronized. This is common when the data stored in the database is different than the data used in the bean fields. The methods might be used, for example, to compress data before it is stored and decompress it when it is retrieved from the database.


Regards,
Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic