aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Entity Bean Updates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Entity Bean Updates" Watch "Entity Bean Updates" New topic
Author

Entity Bean Updates

Terrence White
Ranch Hand

Joined: Jun 26, 2002
Posts: 39
I have an entity been that gets its data from a table in the database.
If I update the database after the entity bean has been loaded, the fields of the bean are not automatically updated with the database changes.
Is there a method or standard way up updating the bean after the back end data source has changed?
Sri Basavanahally
Ranch Hand

Joined: Oct 07, 2003
Posts: 75
The specs say that the container is supposed to invoke ejbLoad() whenever it sees the need to re-synhronize the bean state with the database. So, in other words it is automatic. The bean developer does not have anything to do with this.If you want to sync your instance variables with the database values, you would do that as part of ejbLoad().


UP THE IRONS !
Sri Basavanahally
Ranch Hand

Joined: Oct 07, 2003
Posts: 75
Also, the specs says the following:
After the first ejbLoad within a transaction, the container is not required to recognize that the state of the entity object in the database has been changed by another transaction, and it is not required to notify the instance of this change via another ejbLoad call.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
This is why there is a difference between the Option A, B and C Caching policies in the EJB spec. Briefly, the assumption is that if you have a short enough bean lifetime that the database won't change underneath you. So option C caching (which means the bean instance lasts only as long as the outermost EJB transaction) combined with a database locking strategy like a SELECT FOR UPDATE is usually the way that this is handled.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Entity Bean Updates