-->
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.  [ 7 posts ] 
Author Message
 Post subject: Lock table
PostPosted: Thu Apr 26, 2007 7:33 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
Hi,

I have a database where a lot of people insert data at the same time. For this data, the primary keys are generated with triggers in the database. So I have to lock the whole table when I want to insert an object. How can I do this? Especially I don't only have to lock only one table but at least 3 or 4 at the same time, because there are FK relations between the data.

Hibernate version: 3.2 beta 8

Name and version of the database you are using: Oracle 10g


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 1:36 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I don't even know if Oracle is able to lock an entire table. Isn't able to lock at the row level?

Maybe see the Session.lock() method and what the values are for the LockMode parameter.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 2:06 pm 
Newbie

Joined: Fri Apr 20, 2007 3:46 pm
Posts: 15
If you must lock the whole table in oracle you can do with this command

LOCK TABLE TABLE_NAME IN EXCLUSIVE MODE

You can issue this command in hibernate just through the regular sql.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 2:09 pm 
Newbie

Joined: Fri Apr 20, 2007 3:46 pm
Posts: 15
But I forgot to say that locking the whole table and locking other tables is very bad regarding the performances, especially if you have quite a few threads.

I don't know your business use case but you should try to avoid the strategy of locking tables.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 5:17 pm 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
You don't need to lock tables if your using Hibernate... regardless of DB or FKs, I'd of thought. If your using a native/sequence PK then Hibernate and your DB will take care of inserting new records in paralle for you.
Right?
Also wasn't there already a thread on this?

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 28, 2007 2:38 pm 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
Yes, you're right, that hibernate takes care that my primary keys are generated unique but I think that there will be some situations where I'll have to lock a whole table. Especially when I have to make sure that nobody writes data during some select statements.
I know that locking a table isn't good for the performance but in the moment the most important thing is that it works. The speed up comes later. ^^
Thank you all for your help!!!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 28, 2007 2:46 pm 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
I'd say that if you are having to lock an entire table then there is a more fundimental architecture issue that you need to look at. If you leave it until you are having performace issues it could be too late and you could find yourself faced with a real headache.

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


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