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?
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 !
Joined: Oct 07, 2003
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.
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