• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Hibernate] Please explain hilo generator

 
Joshua White
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to hibernate. I have been able to successfully insert object into my MS SQL database using the hilo generator. The problem is, it is not working like I think it should.

Given the tables TICKET and TICKET_SEQUENCE, I see that TICKET_SEQUENCE.ID is being incremented by 1 like it should. TICKET.ID on the other hand, is being incremented by 2 (1,3,5,7,9,11 etc). What is happening here?

Regards,

Joshua
 
Joshua White
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, moving one step closer. I had my max_low value set to 1.

Still, if my sequence table started at zero and I specified a max_low value of 100 and performed 50 new inserts (and I see 1-50 inserted in the DB), why is my sequence table only set to 1 and not 100?

If I ever decided to change my max_low value, it would seem that I would be screwed. Could someone clarify this?

Joshua
 
Loren Rosen
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I recall corrrectly, with the Hibernate implementation of hilo, the sequence value stored is not the starting number of the next block of sequence numbers, but the number of the next sequence block, which will be multiplied by the block size to get the block starting number.

Thus if the block size is 100, it works this way
sequence 1, give out id's 1...100, then
sequence 2, give out id's 101...200, then
sequence 3, give out id's 201...300, etc.
 
Joshua White
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

Using your example, I was hoping to clarify why 1,2,3 were stored in the sequence table instead of 100,200,300.

If I had a value of 2 in my sequence table (and had specified a low value of 100) what would happen if I wanted to switch to a low value of 10?

Joshua
 
Loren Rosen
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming my understanding is correct, you would have to manually adjust the value in the sequence table so as to avoid giving out sequence numbers that were already in use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic