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.  [ 1 post ] 
Author Message
 Post subject: MultipleHiLoPerTableGenerator cannot handle long
PostPosted: Tue Sep 26, 2006 11:53 am 
Newbie

Joined: Tue Sep 26, 2006 7:51 am
Posts: 1
Location: Reading, UK
Hibernate version:3.1


<id name="id" type="long" unsaved-value="null">
<column name="DataId" />
<generator class="org.hibernate.id.MultipleHiLoPerTableGenerator">
<param name="table">tblSequenceTable</param>
<param name="primary_key_column">SequenceName</param>
<param name="value_column">NextVal</param>
<param name="primary_key_value">tblData</param>
<param name="max_lo">1000</param>
</generator>
</id>


Name and version of the database you are using:SQL Server 2005

I use hibernate to generate primary keys using the org.hibernate.id.MultipleHiLoPerTableGenerator class. With a NextVal value of 15974085 in the tblSequenceTable, the ids are being generated as a negative value. Seems like the org.hibernate.id.MultipleHiLoPerTableGenerator cannot handle values greater than Integer.MAX_VALUE, even though the javadoc says
Quote:
A hilo IdentifierGenerator that returns a Long, constructed using a hi/lo algorithm
.

Looking at the source for this class, the generate() method can only return values in the Integer range as it casts the value returned from the doWorkInCurrentTransaction() method to an integer. If the hival is greater than Integer.MAX_VALUE then this method will return a random number which is the result of truncating the size to an integer.

I was able to resolve this issue by changing the Integer to Long where applicable in the MultipleHiLoPerTableGenerator class.

I think the javadoc for this class is somewhat misleading and it should also mention that the class cannot handle values greater than Integer.MAX_VALUE (even though the returned value is Long when the type of the id is long).
A better solution is for MultipleHiLoPerTableGenerator to be able to generate Long ids greater than Integer.MAX_VALUE without truncating.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.