aspose file tools*
The moose likes Object Relational Mapping and the fly likes [Hibernate] Please explain hilo generator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[Hibernate] Please explain hilo generator" Watch "[Hibernate] Please explain hilo generator" New topic
Author

[Hibernate] Please explain hilo generator

Joshua White
Ranch Hand

Joined: Jun 04, 2001
Posts: 97
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

Joined: Jun 04, 2001
Posts: 97
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

Joined: Feb 12, 2003
Posts: 156
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

Joined: Jun 04, 2001
Posts: 97
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

Joined: Feb 12, 2003
Posts: 156
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Hibernate] Please explain hilo generator