-->
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.  [ 2 posts ] 
Author Message
 Post subject: auto-increment key returns the same value across sessions
PostPosted: Mon Mar 14, 2005 6:56 pm 
Newbie

Joined: Thu Mar 25, 2004 8:58 pm
Posts: 1
Hibernate version: 2.1.6
Mysql 4.0.x
consider the following table 'machine', where id_machine is autoincrement.
Code:
id_machine, name, description, platform
1                   s1      desc1          fedora1
2                   s2      desc2          fedora2

The relevant part of the mapping in the hbm file looks like this.
Code:
...
    <id name="idMachine"
        column="id_machine"
        type="long">
        <generator class="increment"></generator>
    </id>
...


* Consider 2 different sessions on different machines trying to insert into the table at the same time, the auto increment logic would get the value '3' for both the sessions.
* When tried to commit, only the first session succeeds while the other failes with net.sf.hibernate.exception.ConstraintViolationException.

Is there a way to avoid this?

Thanks for the great tool.
- Vinay


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 7:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use generator="native" or generator="identity" - and read the reference manual on what generator does what.


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