-->
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: Data Concurrency
PostPosted: Sun Dec 09, 2007 11:12 pm 
Newbie

Joined: Sun Dec 09, 2007 10:56 pm
Posts: 1
Hello,

I've been tasked to fix a bug on a legacy system that is using Hibernate version 2. I'm very new to Hibernate and I've found some similar questions and answers in the forums but none have worked.

It's a system that assigns user number based on a sequence. So you select the value and then update it by 1. The problem is there are multiple servers hitting a SQL Server 2005 database and if the ID is selected and updated at the same time there are duplicate numbers assigned.

Code:

Query hibernateQuery = hibernateSession.createQuery("from UserSeq as user where user.seqName = :seqName");
         hibernateQuery .setLockMode("user", LockMode.UPGRADE);

hibernateQuery .setString("seqName", "SEQ_NAME");

List result = hibernateQuery .list();

.....

user.setValue(seq + 1);




From what I read this should lock at the row level but it does not. The other servers can get the same number even after the first server has updated the sequence. Is there an alternate way that someone knows of updating this ID? Is there a bug in Hibernate 2 with LockMode.UPGRADE?

Any help would be appreciated.

Thanks,
Lewis


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 2:55 am 
Beginner
Beginner

Joined: Fri Jun 25, 2004 11:47 am
Posts: 34
I'm suspecting your code posted is maybe not working as expected, particulary, you should turn on the SQL output and check that you have SELECT .... FROM ... FOR UPDATE.

Additionnaly, if all your database call are going through hibernate, why don't you use the strategy for id generation as explained in hibernate doc (5.1.4.2. Hi/lo algorithm). I'm just not sure if it apply to hibernate 2....


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.