-->
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.  [ 4 posts ] 
Author Message
 Post subject: Incremental ID and assignment
PostPosted: Wed Mar 02, 2005 5:30 pm 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Hibernate version: 2.1.7
Name and version of the database you are using: Sybase

Hello all !
1)How does Hibernate generates an incremental id(primary key) !?
2)just when i call save !?
3)or when the transaction is commited ?!So hibernate calls select max and assign the key ?!
4) There is a chance to happens a "bug" , when Hibernate generates the same identifier to two different objects ?!


It´s better to use my own generated identifiers !?


Thank you very much!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 9:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Use the native generator.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 10:22 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 8:47 am
Posts: 32
Location: Brazil State:Rio Grande do Sul City:Porto Alegre
Thank you david but i´m a newbie user and need some explanation about how Hibernate assigns an Id, how it works.
I did not find anything about my question.

Suppose i have two users doing an insert operation in different web transaction.

operationOne
session.save(objectOne)

1) now Hibernate goes to database select max id, add one and sets it to the object !?
2) or then just when the transaction is committed it´s assigned calling session.flush?



operationTwo
differentSession.save(objectTwo)

3) between that operation another is saving an object and assigns an id, so there is a possibility of two different objects to have the same identifier (selecting does not use lock) ?!
4) Even if hibernates generates it on transacion.commit() ?!


Sorry by english, and thanks again !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 9:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The native generator uses the native database's method of getting the next id usings its own semantics. For example, MSSQL uses an auto number so its the database's job to allocate the id when each record is inserted. Its the DBs responsibility to serialise this operation to guarantee no conflicts.


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