-->
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: seqhilo: Discrepancy between HB and sequence ids
PostPosted: Mon Sep 22, 2003 7:34 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
Hi,

I' getting some weird id numbers generated for the following declaration on Postgresql:

Code:
        <id name="id" type="long">
            <generator class="seqhilo">
                <param name="sequence">ProductSeq</param>
                <param name="max_lo">100</param>
            </generator>
        </id>


My assumption was that if next value id equals, say, 100 and max_lo=100 (see above) then HB will use number from 100 to 200 next id numbers (as it would be in the underlying sequence in Postgresql). However, HB uses some strange logic to generate ids that are in the range of 11000+. Why is this necessary? For me it creates a problem since now there's mismatch between sequence values in HB and Postgresql and, as a result, scripts that directly work with Pg sequences (and not through HB) may break.

Any ideas? Thanks


Code:
public synchronized Serializable generate(SessionImplementor session, Object obj) throws SQLException, HibernateException {
      
      if ( lo>maxLo ) {
         long hival = ( (Number) super.generate(session, obj) ).longValue();
         lo = 1;
         hi = hival * ( maxLo+1 );
         log.debug("new hi value: " + hival);
      }
      
      return IdentifierGeneratorFactory.createNumber( hi + lo++, returnClass );
   }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 11:32 am 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
OK, let me rephrase it somewhat:

The current logic for seqhilo creates the following problems:

1) Id numbers generated by HB and the real sequence itself are not the same.

2) If "max_lo" number is changed during the life of the project, it may result in generation of the same Id numbers again

Why not use

Code:
SELECT setval('foo', 42);

to reserve a block of Ids (the code for Postgresql)?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 3:10 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:20 am
Posts: 40
Location: Vienna
Hi,
as far as I understand it, the value in the table used to generate the ids is always incremented by 1 only. So in order to use several IDs, the value in the table is multiplied with (maxLo + 1), thereby giving you maxLo+1 IDs that can be used.
This has the drawback that all programs using this table to generate IDs must implement this logic AND use the same max_lo.

regards
Stefan


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.