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