-->
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.  [ 3 posts ] 
Author Message
 Post subject: Locking a table
PostPosted: Sun Jun 20, 2004 4:32 pm 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Hi all,

I'm experimenting a problem of unique contraint violation when trying to insert in a table.

I need at an application level to make sure that an instance of a table called X here won't be modified by both client at the same time, so I have implemented kind of a lock process.

So before a client try to modify an instance of X, it checks before if there is an entry in the locktable referencing the instance of X.
If not, it inserts a entry into the locktable and delete it after having finished. My problem is that between the moment where I check if there is an entry in X and if not the moment where I do commit the insert of the entry in X, another client has already inserted one entry, so I get a constraint violation.

The question is there another way except handling the exception and trying again a few moment later to do this, I mean kind of a table locking stuff?

Vlad


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 20, 2004 4:37 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use session.lock(LockMode) and a database that supports pessimistic locks and "FOR UPDATE" SQL. Don't implement locking yourself.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 20, 2004 4:40 pm 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Ok,

But session.lock is applicable to an object and in my case, I do not have yet persisted it ; what I'd like to do is maybe something like locking to whole table?

Vlad


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