-->
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: How Hibernate generates id using generator-class="incre
PostPosted: Fri Nov 04, 2005 3:35 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 4:32 am
Posts: 29
Location: Cluj-Napoca
Does anybody has a more detailed answer at this question ?

All that exists in the documentation 2.1.7 is:
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.

Thanks, Cristian.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 4:41 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
hibernate assigns the identifier, as opposed to you or the db. the identifier is incremented each time and you cannot do this in a cluster because app1 will try to insert a row w/ an identifier property that has already been used by app2.

hibernate team, are there non-obvious technical challenges to a "distributed increment" identifier ? is there just not enough demand for this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 4:47 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 4:32 am
Posts: 29
Location: Cluj-Napoca
Hi Dennis,

Do you know the algorithm that Hibernate uses to increment the id ?
I mean, does it use a select max(id) to determine the start point or what ?

Thanks, Cristian.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 5:06 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 4:32 am
Posts: 29
Location: Cluj-Napoca
Hi everybody,

I have found into Hibernate in Action book (page 91) the following explanation:

At Hibernate startup, this generator reads the maximum primary key column value of the table and increments the value by one each time a new row is inserted.
The generated identifier is of type long, short, or int.
This generator is especially efficient if the single-server Hibernate application has exclusive access to the database but shouldn’t be used in any other scenario.

Now everything is clear regarding this subject.

See you soon, Cristian.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 5:08 am 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
crista wrote:
Hi everybody,

I have found into Hibernate in Action book (page 91) the following explanation:

At Hibernate startup, this generator reads the maximum primary key column value of the table and increments the value by one each time a new row is inserted.
The generated identifier is of type long, short, or int.
This generator is especially efficient if the single-server Hibernate application has exclusive access to the database but shouldn’t be used in any other scenario.

Now everything is clear regarding this subject.

See you soon, Cristian.


Right, the "highest value" is held somewhere within the JVM, with a lock around it. If some other JVM (or anything else) had write access to that table it wouldn't work.


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.