-->
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: Unable to delete batch updated objects
PostPosted: Wed Sep 03, 2008 11:17 am 
Newbie

Joined: Mon Jan 21, 2008 7:30 am
Posts: 9
I want to be able to select some rows from a table, update a value in a column and persist this update back to the db for each row.

Code:
ScrollableResults cashflows = query.setParameter("farDate", farDate, Hibernate.DATE).
            setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);
      int count=0;         
      ArrayList<PendingCashFlow> results = new ArrayList<PendingCashFlow>();
      while(cashflows.next()) {
         PendingCashFlow pcf = (PendingCashFlow) cashflows.get(0);
         pcf.setProcessingState(ProcessingState.PROCESSING);
         session.update(pcf);
         results.add(pcf);         
          if ( ++count % 50 == 0 ) {
              session.flush();
          }
      }
       session.flush();
       cashflows.close();


In the code above, setting the ProcessingState means that other processes won't select the row and attempt to process it. Further processing will then take place, and at a later point I want to delete these rows from the table.
I call getHibernateTemplate().deleteAll() passing in the list of PendingCashFlows obtained from the code fragment above. When this line of code is executed, the method doesn't return, and no rows are deleted or exception thrown. If I return the PendingCashFlows from a regular findByNamedQuery call, and don't update anything, then the call to deleteAll succeeds.

The only reason I can think of for this happening is that the PendingCashFlows are not bound to the session by the batch update, but I haven't called session.clear() to clear the persistence context, so I'm baffled as to what the problem is. Can anyone shed light on this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2008 8:48 am 
Newbie

Joined: Mon Jan 21, 2008 7:30 am
Posts: 9
Solved the problem. This was due to the fact I was executing the deleteAll method in another thread, which had it's own session, which didn't know about the PendingCashFlows loaded in the other thread's session.


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.