-->
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.  [ 5 posts ] 
Author Message
 Post subject: Record Locking
PostPosted: Tue Feb 17, 2004 9:10 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
Hi all!

I'm currently trying to generate my primary keys based on a table that is held in my DB. For example, I have a table that has a table (PRIMARY_KEY) that consists of columns "TABLE_NAME" and "PRIMARY_KEY_VALUE". An example of a record that might exist in this table is:

TABLE_NAME, PRIMARY_KEY_VALUE

RESOURCE, 1000

What I want to do when I insert a new record into the RESOURCE table is to pull the next value for the primary key of RESOURCE out of my PRIMARY_KEY table. So, in the example above, I want to first get the current value (1000), increment it by one, replace the new value (1001), and then use this new value as the primary key for the Object I'm inserting into the RESOURCE table.

My problem comes from trying to get a WRITE lock on the record before I actually update it. A READ lock isn't good enough because there will be an issue of someone reading the same record between the time that I read it and re-write it. I looked into the UPGRADE lock, but my application needs to be database-independent, so that isn't really an option. Does anybody have any ideas on how I can successfully accomplish this? BTW - unfortunately, changing the primary key strategy is not an option.


Thanks in advance for any help that anyone can offer!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 3:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/hib_docs/reference/html_single/#or-mapping-s1-4--generator
You'll find everithing you want and even more :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 1:02 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
Thank you very much for the response emmanuel, but I'm a little confused about your reply. I don't want Hibernate to be responsible for updating my table of primary keys. I want that to be managed solely by the application, without the use of one of Hibernate's generators, save the assigned designator.

I'm struggling with finding a way to lock a record in the DB so that nobody else can read or write it, update that record, and then store the new value.

If your answer contained a method for solving my situation, I apologize for not understanding. I appreciate the response, but I think that the only thing I'm going to use a generator for is to set it to assigned and pull the key from my primary key table.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 1:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There are some goods implementations of the main id generator concepts, have a look at the code and inspire you.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 1:21 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
OK..will do. Thank you very much!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.