-->
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.  [ 2 posts ] 
Author Message
 Post subject: StaleObjectStateException with MDB
PostPosted: Wed Feb 02, 2011 1:35 am 
Newbie

Joined: Wed Sep 16, 2009 1:24 am
Posts: 9
Hi there,

I am having a message driven bean(MDB) running in two servers(server1 and server2 -clustered Websphere server), each server will have its own listener port listening to a queue.Once a message has been placed in the queue, the MDB will pick the message and insert the parsed date into a db2 table(SecurityNotificationDetail ).

These are the hibernate objects that MDB will use to update to database

    SecurityNotificationDetail - The XML message will be parsed and stored to this table.(having many-to-many relation to LendingApplicationTest table).
    LendingApplicationTest - This will have a set of SecurityNotificationDetail.


Code:
SecurityNotificationDetail
/**
* <p>
* This PD class will store the security update notify messages from the
* security register. This class can be populated by an MDB.Once all the updates
* has been proceessed for a customer and security, the related records will be
* deleted from this class.
* </p>
*
* @hibernate.class table="TEST_SECURITY_NOTIFICATION_DETAIL"
*
*
*
*/
public class SecurityNotificationDetail  implements Cloneable  {

   /**
    * <p>Logger</p>
    */
    private static Logger LOG = Logger.getLogger(SecurityNotificationDetail.class);
   /**
    * ID for the security notification detail
    */
   private Long oid;

   /**
    * Holds the modification flag for security update action
    */
   private String actionType;

   /**
    * Holds the security number of the security got updated in SR
    */
   private String securityNumber;

   /**
    * Holds the security type in SR
    */
   private String securityType;

        /**
    * Holds field list that has got modified in SR
    */
   private String fieldList;

   /**
    * Holds the last updated time stamp of the notify message recorded by SR.
    */
   private Timestamp notifiedTimeStamp;

   /**
    * Holds the last updated time of the security update notification record in
    * NZLO DB
    */
   private Timestamp lastUpdatedDate;

   /**
    * Holds the created date of the security update notification record in NZLO
    * DB
    */
   private Timestamp createdDate;

   /**
    * Holds the created user of the security update notification record in NZLO
    * DB
    */
   private String createdBy;

   /**
    * Holds the last updated user of the security update notification record in
    * NZLO DB
    */
   private String lastUpdatedBy;

   /**
    * Holds the last updated version of the security update notification record
    * in NZLO DB
    */
   private Long lastUpdatedVersion;
   
   
   
   /**
    * @hibernate.property column="CREATED_DATE"
    * @return the createdDate
    */
   public Timestamp getCreatedDate() {
      return createdDate;
   }

   /**
    * @param createdDate
    *            the createdDate to set
    */
   public void setCreatedDate(Timestamp createdDate) {
      this.createdDate = createdDate;
   }

   

   /**
    * @hibernate.property column="FIELD_LIST" length="1000"
    *
    * @return the fieldList
    */
   public String getFieldList() {
      
      return fieldList;
   }

   /**
    * @param fieldList
    *            the fieldList to set
    */
   public void setFieldList(String fieldList) {
      this.fieldList = fieldList;
   }

   /**
    * @hibernate.property column="LAST_UPDATED_BY" length="8"
    * @return the lastUpdatedBy
    */
   public String getLastUpdatedBy() {
      return lastUpdatedBy;
   }

   /**
    * @param lastUpdatedBy
    *            the lastUpdatedBy to set
    */
   public void setLastUpdatedBy(String lastUpdatedBy) {
      this.lastUpdatedBy = lastUpdatedBy;
   }

   /**
    * @hibernate.property column="LAST_UPDATED_DATE"
    * @return the lastUpdatedDate
    */
   public Timestamp getLastUpdatedDate() {
      return lastUpdatedDate;
   }

   /**
    * @param lastUpdatedDate
    *            the lastUpdatedDate to set
    */
   public void setLastUpdatedDate(Timestamp lastUpdatedDate) {
      this.lastUpdatedDate = lastUpdatedDate;
   }

   /**
    * @hibernate.version column="LAST_UPDATED_VERSION"
    * @return the lastUpdatedVersion
    */
   public Long getLastUpdatedVersion() {
      return lastUpdatedVersion;
   }

   /**
    * @param lastUpdatedVersion
    *            the lastUpdatedVersion to set
    */
   public void setLastUpdatedVersion(Long lastUpdatedVersion) {
      this.lastUpdatedVersion = lastUpdatedVersion;
   }

   /**
    * @hibernate.id generator-class="native"
    *               column="SEC_NOTIFICATION_DETAIL_ID"
    * @return Returns the oid.
    */
   public Long getOid() {
      return oid;
   }

   /**
    * @param oid
    *            the oid to set
    */
   public void setOid(Long oid) {
      this.oid = oid;
   }

   /**
    * @hibernate.property column="ACTION_TYPE" length="1"
    *
    * @return the actionType
    */
   public String getActionType() {
      return actionType;
   }

   /**
    * @param actionType
    *            the actionType to set
    */
   public void setActionType(String actionType) {
      this.actionType = actionType;
   }

   /**
    * @hibernate.property column="SECURITY_NUMBER" length="10"
    *
    * @return the securityNumber
    */
   public String getSecurityNumber() {
      return securityNumber;
   }

   /**
    * @param securityNumber
    *            the securityNumber to set
    */
   public void setSecurityNumber(String securityNumber) {
      this.securityNumber = securityNumber;
   }

   /**
    * @hibernate.property column="SECURITY_TYPE" length="5"
    *
    * @return the securityType
    */
   public String getSecurityType() {
      return securityType;
   }

   /**
    * @param securityType
    *            the securityType to set
    */
   public void setSecurityType(String securityType) {
      this.securityType = securityType;
   }
   
   
   /**
    * @hibernate.property column="CREATED_BY" length="8"
    * @return the createdBy
    */
   public String getCreatedBy() {
      return createdBy;
   }

   /**
    * @param createdBy
    *            the createdBy to set
    */
   public void setCreatedBy(String createdBy) {
      this.createdBy = createdBy;
   }

   /**
    * @hibernate.property column="NOTIFIED_TIMESTAMP"
    * @return the notifiedTimeStamp
    */
   public Timestamp getNotifiedTimeStamp() {
      return notifiedTimeStamp;
   }

   /**
    * @param notifiedTimeStamp
    *            the notifiedTimeStamp to set
    */
   public void setNotifiedTimeStamp(Timestamp notifiedTimeStamp) {
      this.notifiedTimeStamp = notifiedTimeStamp;
   }

   

   }


LendingApplicationTest
Code:
/**
* @hibernate.class table="TEST_APPLICATION" lazy="true" batch-size="5"
*/
public class LendingApplicationTest {

   private Long       oid;
   
   private String       appNumber;
   
   private String       appName;
   
      
   /**
    * @hibernate.property column="APP_NAME"
    */
   
   public String getAppName() {
      return appName;
   }

   public void setAppName(String appName) {
      this.appName = appName;
   }

   /**
    * @hibernate.property column="APP_NUMBER"
    */
   public String getAppNumber() {
      return appNumber;
   }

   public void setAppNumber(String appNumber) {
      this.appNumber = appNumber;
   }

   /**
    * @hibernate.id generator-class="native" column="APP_ID"
    * @return Returns the oid.
    */
   public Long getOid() {
      return oid;
   }

   /**
    * @param oid The oid to set.
    */
   public void setOid(Long oid) {
      this.oid = oid;
   }

      private Set securityNotificationDetails = new HashSet();
   
      
   /**
              * @hibernate.set inverse="false" table="TEST_LA_SECURITY_NOTIFICATION_DETAIL" lazy="true"
              * @hibernate.collection-key column="APP_ID"
              * @hibernate.collection-many-to-many class="com.ram.updates.SecurityNotificationDetail"
              * column="SEC_NOTIFICATION_DETAIL_ID"
              * @return securityNotificationDetails
              */
   public Set getSecurityNotificationDetails() {
      return securityNotificationDetails;
   }

   /**
    * @param securityNotificationDetails the securityNotificationDetails to set
    */
   public void setSecurityNotificationDetails(Set securityNotificationDetails) {
      this.securityNotificationDetails = securityNotificationDetails;
   }
   
   
   
   /**
    * <p>
    * This method will list out all the lending applications for the given
    * security number and update lending applications with the security update
    * flag and also it will identify the lending applications for which the
    * security update message cannot be displayed.
    * </p>
    *
    * @param crsNumberList
    * @param securityNumber
    * @return boolean
    * @throws Exception
    * @throws PersistenceException
    */
   public static boolean updateLendingApplicationsWithSecurityUpdateFlag(
         Session session ,SecurityNotificationDetail notification)
   {

       List lendingApplist = new ArrayList();
       LendingApplicationTest applicationTest = new LendingApplicationTest();
       session.load(applicationTest, new Long(4));
       lendingApplist.add(applicationTest);

       LendingApplicationTest applicationTest1 = new
       LendingApplicationTest();
       session.load(applicationTest1,new Long(5));
       lendingApplist.add(applicationTest1);

       LendingApplicationTest applicationTest2 = new
       LendingApplicationTest();
       session.load(applicationTest2,new Long(6));
       lendingApplist.add(applicationTest2);
      
      Iterator lendingAppItr = lendingApplist.iterator();
      while (lendingAppItr.hasNext())
      {
         LendingApplicationTest application = (LendingApplicationTest) lendingAppItr
               .next();
         
         //doing some work to find the valid one. 
         Set securityNotificationSet = application.getSecurityNotificationDetails();
         securityNotificationSet.add( notification );
         //Set LANotificationSet = notification.getLendingApplications();
         //LANotificationSet.add( application );
         //I suspect, here is the place where I am getting the StaleStateObjectException.
         session.update(application);
            
      }
      return true;
   }
   
   
}


The problem is I am getting "org.hibernate.StaleObjectStateException", when I tried to update the lending applicationtest table. From the analysis,I discovered so far is when Message m1 and Message m2 processed by two different MDB instances may be trying to update the same application.Am I correct? Can you please give a solution to resolve this issue ?

Can I use "synchronized" block for updating the lendingapplicationtest table (inside updateLendingApplicationsWithSecurityUpdateFlag method) ? will it impact the performance ?

Appreciate your help to solve this issue.
Thanks in advance.

StackTrace:

Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.sample.pd.lendingapplication.LendingApplication#931971]
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.westpac.nzlo.pd.lendingapplication.LendingApplication#931971]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java(Compiled Code))
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java(Compiled Code))
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java(Compiled Code))
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java(Compiled Code))
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java(Compiled Code))
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java(Inlined Compiled Code))
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java(Compiled Code))
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java(Compiled Code))
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java(Compiled Code))
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java(Inlined Compiled Code))
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java(Compiled Code))
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java(Compiled Code))
at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java(Compiled Code))
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$1.invoke(WebSphereExtendedJTATransactionLookup.java(Compiled Code))
at $Proxy1.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java(Compiled Code))
at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java(Compiled Code))
at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrepare(TransactionImpl.java(Compiled Code))
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java(Compiled Code))
at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java(Compiled Code))
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java(Compiled Code))
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java(Compiled Code))
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java(Compiled Code))
at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java(Compiled Code))
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java(Compiled Code))
at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java(Compiled Code))
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java(Compiled Code))
at com.sample.framework.serviceexecutor.EJSLocalStatelessServiceExecutorEJB_e5d362d6.executeWithTransaction(Unknown Source)
at com.sample.ui.service.securityupdates.SecurityUpdateNotifierSystem.processSecurityUpdates(SecurityUpdateNotifierSystem.java(Compiled Code))
at com.sample.security.SecurityUpdateNotifierBean.onMessage(SecurityUpdateNotifierBean.java(Compiled Code))
at com.ibm.ejs.jms.listener.MDBWrapper$PriviledgedOnMessage.run(MDBWrapper.java(Compiled Code))
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java(Inlined Compiled Code))
at com.ibm.ejs.jms.listener.MDBWrapper.callOnMessage(MDBWrapper.java(Compiled Code))
at com.ibm.ejs.jms.listener.MDBWrapper.onMessage(MDBWrapper.java(Compiled Code))
at com.ibm.mq.jms.MQSession.run(MQSession.java(Compiled Code))
at com.ibm.ejs.jms.JMSSessionHandle.run(JMSSessionHandle.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSession.connectionConsumerOnMessage(ServerSession.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSession.onMessage(ServerSession.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSession.dispatch(ServerSession.java(Inlined Compiled Code))
at sun.reflect.GeneratedMethodAccessor1129.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSessionDispatcher.dispatch(ServerSessionDispatcher.java(Compiled Code))
at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java(Compiled Code))
at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSession.run(ServerSession.java(Compiled Code))
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))


Top
 Profile  
 
 Post subject: Re: StaleObjectStateException with MDB
PostPosted: Sun Feb 13, 2011 6:48 pm 
Newbie

Joined: Wed Sep 16, 2009 1:24 am
Posts: 9
Hi, Can any hibernate experts please look into this issue ?


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

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.