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.  [ 6 posts ] 
Author Message
 Post subject: Does hibernate support row level or table level locking?????
PostPosted: Thu Dec 02, 2004 5:55 pm 
Newbie

Joined: Wed Nov 24, 2004 8:38 am
Posts: 19
Location: India
Does hibernate support row level or table level locking?????
I using "WAP T" as a testing tool to test a test case scenario wuth HIBERNATE 2.1.6 and MYSQL 4.0 as database. The scenario is that 10 simultaneous users are trying to insert 100 records each. I am having servlet where i have a loop from 1 to 100, to insert records in the database. I have set the primary key id to auto increment in the hbm.xml file.

On running this test case some records are inserted and then after that there is an runtime exception that "u r trying to insert multiple records for the id <id no.>".

This means, suppose when user 1 and user 2 come simultaneously to obtain connection to database and after that user 1 has inserted 20 records and after that when user 2 tries to insert records, the count starts from 1 bcoz it was having the info that database has no records.

I tried the same scenario by removing the primary key constraint on id and it went absoulutely fine. It inserted 1000 records in the database but the id field was having multiple values....

So I concluded that either MYSQL or HIBERANTE does support the LOCKING mechanism....

Can any one comment on this conclusion. If locking mechanism is not there with HIBERNATE or MYSQL then how should i handle the situation.

Thanks........


Top
 Profile  
 
 Post subject: plz comment........
PostPosted: Fri Dec 03, 2004 11:00 am 
Newbie

Joined: Wed Nov 24, 2004 8:38 am
Posts: 19
Location: India
Plz. Comment


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 03, 2004 1:25 pm 
Beginner
Beginner

Joined: Thu Oct 14, 2004 9:50 am
Posts: 43
What was the generator on your mapping? Some generators are specifically documented as not handling concurrency very well. Try switching the generator to something like sequence.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 04, 2004 1:24 am 
Newbie

Joined: Wed Nov 24, 2004 8:38 am
Posts: 19
Location: India
Hi eg344,

I am using the mapping something like this:

<id name="id" type="long" column="uid" unsaved-value="0">
<generator class="increment">
</generator>
</id>

The generator here is "increment".

In the hibernate reference manual there are other generators as you talked about...

increment
generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster.
identity
supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier is of type long, short or int.
sequence
uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in Interbase. The returned identifier is of type long, short or int

Its a clear interpretation that increment is ruled out and also as i am using MYSQL so i need to use "identity" as the generator.

But its not clear if it will solve the problem... I need to test it first....

Can you add more to it.....

Thanks for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 04, 2004 6:26 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster.

This does not work in your scenario, since every parallel servlet invocation does run in its own thread.

Identity or even betterh uuid will work fine in your scenario.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 12:42 am 
Newbie

Joined: Wed Nov 24, 2004 8:38 am
Posts: 19
Location: India
Thanks ernst.....


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