-->
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: Preventing concurrent read
PostPosted: Sun Jan 15, 2012 3:21 am 
Newbie

Joined: Sun Jan 15, 2012 2:47 am
Posts: 1
Hi,
In my application, I am processing the records in batches. For that I have created a batch table which contains 3 columns viz. Batch_Id, Processing_Time and Status. I have multiple instances of my application.

Processing_Time field is kept to find the scenarios where a batch processing might have started earlier but due to some condition, application is crashed mid-way. So if a record in batch table has status=2 and processing time earlier than 10 minutes, I can safely assume that it's a failed batch and need to reprocess. After successful batch processing, status is moved to 4.

My select query for batch id has where clause as status=2 and Processing_Time is earlier than 10 minutes. Now as told earlier, due to multiple installations, multiple threads are picking up the same batch id though I have written SELECT for UPDATE query and immediately updating the Processing_Time of least batch id to current time. I am using Hibernate native query i.e. session.createSQLQuery().

How can I make one thread to wait using Hibernate till my SELECT FOR Update + Update of one thread gets over so that when second thread starts, it will pick up the next record? Currently what is happening is that Query.uniquResult() returns the same object/row to both the threads and not locking the db? I have also tried to see how can use lock() of session or Query. Session.lock is applicable on object itself so which I don't have before executing query so it is of no use. Can I use Query.lock()? But then what should I specify as "alias" as I am using native query?

Appreciate your help :)

Nilesh Soni


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.