-->
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.  [ 3 posts ] 
Author Message
 Post subject: <table-generator> and the resulting ID
PostPosted: Tue Feb 13, 2007 12:03 pm 
Newbie

Joined: Tue Feb 13, 2007 10:27 am
Posts: 4
Hibernate version: 3.2.1GA

Mapping documents:
Code:
<table-generator name="rm_user" table="xa_sequences" pk-column-name="sequence_name" value-column-name="last_number" pk-column-value="rm_user" allocation-size="1"/>

<entity class="IDUser">
   <table name="rm_user" />
   <attributes>
   <id name="id">
       <column name="user_id" unique="true"/>
       <generated-value strategy="TABLE" generator="rm_user"/>
   </id>
</entity>


As far as I understand section 9.1.38 (TableGenerator Annotation) of the JPA spec, the column defined by value-column-name does contain the last value generated. I.e. if it contains 1, the next entity to be inserted into the database should get 2 as its ID.
The setup for our testcases populates the database with some entries, so we do have some entires in the table rm_user and a corresponding entry in the xa_sequences table with the column last_number set to MAX(rm_user.id). With org.hibernate.id.MultipleHiLoPerTableGenerator used as default ID generator, the next entity to be persisted is assigned the same value MAX(rm_user.id).
Is my intrepretation of the JPA spec incorrect or does the generator indeed return an erroneous value?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 7:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
thing is when the allocationSize != 1 (default to 50), the max strategy doesn't apply anyway.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 4:13 am 
Newbie

Joined: Tue Feb 13, 2007 10:27 am
Posts: 4
emmanuel wrote:
thing is when the allocationSize != 1 (default to 50), the max strategy doesn't apply anyway.

As the allocationSize is set to 1, I do not get the connection...

Let me put it in another way:
- The column last_number contains 1, a user is already present in the db with id 1.
- The app is started, a new user is inserted.
- Hibernate will assign 1 as the next id, which leads to an exception; Toplink e.g. will assign 2 as the next id, which is IMHO as the spec states how it should be.


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