-->
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: Unexpected multiple transactions using Hibernate and Spring
PostPosted: Mon Nov 26, 2007 1:42 am 
Newbie

Joined: Thu Nov 23, 2006 12:33 am
Posts: 1
Hibernate:3.0
Database: Oracle 10g

I have an application using Spring and Hibernate on top of an Oracle 10g database that is performing an unexpected number of transactions. I have the following classes:

Code:
public MatchService
{
   private IBatchDAO mBatchDAO
   private IMatchRecordDAO mMatchRecordDAO

   private Batch getNextBatchForProcessing()
   {
       Batch batch = mBatchDAO.getNextBatch();
       if( batch != null )
       {
           batch.setStatus( Batch.STATUS_PROCESSING );
           mBatchDAO.storeBatch( batch );
        }

        return batch;
   }

   private void processBatch( Batch batch )
   {
      MatchTrx trx = new MatchTrx( mBatchDAO, mMatchRecordDAO );
      trx.processBatch( batch );

      batch.setStatus( Batch.STATUS_COMPLETE );
      mBatchDAO.storeBatch( batch );
   }
}

public MatchTrx
{
   private IBatchDAO mBatchDAO;
   private IMatchRecordDAO mMatchRecordDAO;

   public MatchTrx( IBatchDAO batchDAO, IMatchRecordDAO matchDAO )
   {
      mBatchDAO := batchDAO;
      mMatchRecordDAO := matchDAO;
   }

   public void processBatch( Batch batch )
   {
       MatchRecord rec = mMatchRecordDAO.getMatchRecord( batch.getRecordID();
      rec.updateFromBatch( batch );
      mMatchRecordDAO.deleteOldStuff( rec );
      //... code here creates new stuff ...
      mMatchRecordDAO.storeNewStuff( rec );
   }
}


The MatchService class is wrapped with a transaction proxy bean using Spring, with both public methods declared as transactions. The problem is, when matchService.processBatch() is called, the operations appear to be applied as separate transactions. When the app is terminated in the middle of processBatch, I have found repeatable instances where the call to rec.updateFromBatch( batch ) has updated the database, but any changes made by mMatchRecordDAO.deleteOldStuff( rec ) have been rolled back.

Cany anyone give me some hints about what might be happening here?

Thanks,
Ben


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.