Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Entity Bean Updates

 
Terrence White
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Sri Basavanahally
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic