[jboss-user] [EJB 3.0] - Stateful Bean and the database commit

konstantin.ermakov do-not-reply at jboss.com
Wed Jan 17 03:58:51 EST 2007


Hi!

   I have the following stateful bean:

  | 
  | public class MyStatefulBean implements MyStatefulBeanI,  SessionSynchronization {
  | 
  |   @PersistenceUnit(unitName = "db")
  |   public EntityManagerFactory factory;
  | 
  |   public MyEntity getObject( int id ) throws Exception {
  | 	EntityManager m = factory.createEntityManager();
  |  	return m.find(MyEntity.class, id);
  |   }
  | 
  |   @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  |   public MyEntity update( MyEntity newEntity ) throws Exception {
  | 	EntityManager m = factory.createEntityManager();
  |   	oldEntity e = m.find(MyEntity.class, id);
  | 
  | 	e.setAttribute1( newEntity.getAttribute1() );
  | 	...
  | 	...
  | 	m.flush();
  | 	m.clear();
  |                 m.close();
  |   }
  | 
  |   public void afterCompletion(boolean flag) throws EJBException, RemoteException {
  |      if( flag == true ) {
  |   	sendJMSMessage()
  |      }
  |    }
  | 
  |    .....
  | 
  | }
  | 
  | 

As far as I understood, after update() it is not guaranteed, that the data is in database and commit event already happened. So, as I have the fat clients it can be the case, that after update() was called, getObject() still returns the old entity.

My question is  - is it guarateed, that after the afterCompletion() method the database commit already happened, and it is safe to call getObject() to receive the new data?

Thank you,
Konstantin

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4002646#4002646

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4002646



More information about the jboss-user mailing list