-->
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: TableHiLo generator
PostPosted: Mon Oct 13, 2003 1:02 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Howdy folks,

I've a bit of a problem with the TableHiLo generator. It seems to go back to the DB for every new identifier, instead of only going to the DB every MAX_LO identifiers.

I'm certain it's going to the DB because I use P6Spy to view the SQL being issued and it shows up there, also the hibernate debug logs have a line saying "new hi value: X" for every identifier.

I'm pretty sure this used to work, (in fact I'm sure it probably works for everyone else). Unfortunately we're still running 2.0 beta6. We've plans to change that, but we're stuck on it for the moment.

I looked for an issue in JIRA, but no luck. Anyone know what's happening with this, or is it obvious I've done something braindead?
There aren't any properties to set or something that I've missed?

Cheers,
Shorn.

Details:
An abstract id getter method is defined on our root persistent entity and it's mapped with the following details.

The XDoclet mapping looks like this:
Code:
     * @hibernate:id unsaved-value = "null" generator-class = "net.sf.hibernate.id.TableHiLoGenerator"
     * @hibernate.generator-param name="table" value="cl_id_gen"
     * @hibernate.generator-param name="column" value="n_key_next"

And every object has a concreted getter implementation with doco like this:
Code:
     * @hibernate:id column = "n_key_case"


The generated hbm.xml looks like this:
Code:
        <id
            name="id"
            column="n_key_case"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="net.sf.hibernate.id.TableHiLoGenerator">
                <param name="table">cl_id_gen</param>
                <param name="column">n_key_next</param>
            </generator>
        </id>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 1:00 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Ok, so.... no replies.

I went and looked at the code for TableHiLoGenerator and the code looks a bit suspect, but I thought I'd post here before opening an issue in JIRA.
The code appears to be the same in the latest 20031013 nightly tarball by the way.

TableHiLoGenerator:
Code:
...
private int lo;
private int maxLo;
...
maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
lo = maxLo + 1; // so we "clock over" on the first invocation
...
if (lo>maxLo) {
   int hival = ( (Integer) super.generate(session, obj) ).intValue();
   lo = 1;
   hi = hival * (maxLo+1);
   log.debug("new hi value: " + hival);
}


Given that lo is an integer and will be set to the max short, then isn't the comment 'so we "clock over" on the first invocation' wrong (in that it'll just go to Short.MAX_VALUE+1, since that's a valid integer)?
Then, since lo is maxLo + 1 (and not clocked over) then the condition "if (lo>maxLo)" is going to be true for a good long while - resulting in the super.generate() method being called.

Am I missing something obvious?

Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 7:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
looks just perfect to me.

notice that we set lo=1 after generating the hi value, thus avoiding the possibility that lo>maxLo on the next call.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 7:47 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Ok.
Any ideas what I've done wrong to have the generator go back to the DB each time?


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.