-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JMS Message is getting stale data from Hibernate
PostPosted: Wed Nov 03, 2010 5:09 pm 
Newbie

Joined: Wed Nov 03, 2010 5:04 pm
Posts: 1
I have a managed entity which has a EntityListener attached to it. The EntityListener on PostUpdate and PostPersist adds the entity to a JMS queue to do some more processing. So here is the scenario, I have a session bean which updates the Entity and merges the changes, which in turn triggers the PostUpdate on the listener. But at that point when the MDB starts to consume the JMS message it gets the Entity out of the EntityManager but the Entity it is getting is the old values for that object. Here is the basic code of what I am doing.

Session Bean Method
Code:
@Override
public void updateEntity(Integer entityId, String name) {
   Entity entity = getEntity(entityId);
   entity.setName(name);
   em.merge(entity);
}


Listener Method
Code:
@PostPersist
@PostUpdate
public void afterUpsert(Entity entity) {
    this.entity = entity;
    JMSSubmitter submitter = getSubmitterBean();
    submitter.submit(entity.getEntityId());
}


MDB Code
Code:
@Override
public void onMessage(Message message) {
   TextMessage textMessage = (TextMessage) message;
   try {
      processMessage(textMessage);
   } catch (Exception ex) {
      logger.error("Unable to process the Entity message", ex);
   }
}

private void processMessage(TextMessage message) throws Exception {
   Integer entityId = new Integer(message.getText());
   //Right here I am getting stale data.
   Entity entity = entityBean.getEntity(entityId);
   // ...
   //Some processing is done here
   // ...
   entity.setSomeOtherValue("blah");
            
   entityBean.updateEntity(entity);

}


So my question really is why am I having this problem, I think it is a transaction problem. I think my initial update transaction hasn't commit before the JMS starts consuming the message.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.