-->
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: TableHiLoGenerator Jumps 1 number each lo > maxLo
PostPosted: Mon Nov 12, 2007 11:08 pm 
Newbie

Joined: Mon Nov 12, 2007 10:43 pm
Posts: 7
Hello
I have found one problem in TableHiLoGenerator I compare the source code of hibernate with the nhibernate and the error is only in nhibernate.

When I use the table hilo id generator, the id jumps 1 number each time the lo passes the maxLo because the nhibernate code doesn't have one verification that the hibernate code does.

this is the code in nhibernate TableHiLoGenerator function:

Code:
if (lo > maxLo)
{
   long hival = ((long) base.Generate(session, obj));
   lo = 1;
   hi = hival * (maxLo + 1);
   log.Debug("new hi value: " + hival);
}

return IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass);


And this is the code in hibernate:

Code:
if (lo>maxLo) {
   long hival = ( (Number) super.generate(session, obj) ).longValue();
   lo = (hival == 0) ? 1 : 0;
   hi = hival * (maxLo+1);
   log.debug("new hi value: " + hival);
}


As you can see in hibernate the lo initialization check if it has value 0 to initialize in value 1 or different than 0 to initialize in 0. With this verification the "one number jump" does not happend.

other solution could be not to increment in 1 the hi value.
example:

Code:
if (lo > maxLo)
{
   long hival = ((long) base.Generate(session, obj));
   lo = 1;
   hi = hival * maxLo;
   log.Debug("new hi value: " + hival);
}

return IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass);

I tested this solution and it work fine for me.


I would like to know if I should put this in jira and if I do, like bug or like what?


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.