2

My Oracle database has a sequence (PART_SEQ) starting at 1,000,000,000. My NHibernate mapping uses this sequence for id generation using seqhilo.

  <id name="_persistenceId" column="Id" type="long" access="field" unsaved-value="0" >
     <generator class="seqhilo" >
        <param name="sequence">part_seq</param>
        <param name="max_lo">100</param>
     </generator>
  </id>

I am expecting ids to be generated like 100000000000, 100000000001, 100000000002, ..., 100000000100, 100000000101, 100000000102, ... based on this question and this question.

Instead NHibernate is producing ids like 101000000000, 101000000001, 101000000002, ..., 101000000100, 101000000101, 101000000102 with an extra 1. How is it producing these ids and how can I get it to not add the extra 1 to the id?

Community
  • 1
  • 1
brainimus
  • 10,586
  • 12
  • 42
  • 64
  • 2
    Why do you care about the extra 1? – Lasse V. Karlsen Jun 16 '11 at 20:11
  • It's not that I necessarily care about the 1; it actually helps me in my scenario. What worries me more is it's not working how I expected. I don't really like using something when I don't know what to expect from it. – brainimus Jun 16 '11 at 20:24

1 Answers1

1

Looking at the source here, the implementation of the algorithm adds 1 to the max_lo value before multiplying it by the sequence to generate the hi part. The lo part is then added to this result to create the final id.

For the example in the question it will produce ids in the following manner:

//max_lo is set to 100 when the generator is initialized

if(lo > max_lo)
{
    lo = 1;
    sequence = GetNextSequenceNumber(...);  //Starts at 1 billion
    hi = sequence * (max_lo + 1);
}
returnVal = hi + lo++;

Creating 101000000001, 101000000002, 101000000003, etc.

brainimus
  • 10,586
  • 12
  • 42
  • 64