Questions tagged [hilo]

HiLo algorithm used for generating Ids for databases

The basic idea is that you have two numbers to make up a primary key- a "high" number and a "low" number. A client can basically increment the "high" sequence, knowing that it can then safely generate keys from the entire range of the previous "high" value with the variety of "low" values.

For instance, supposing you have a "high" sequence with a current value of 35, and the "low" number is in the range 0-1023. Then the client can increment the sequence to 36 (for other clients to be able to generate keys while it's using 35) and know that keys 35/0, 35/1, 35/2, 35/3... 35/1023 are all available.

It can be very useful (particularly with ORMs) to be able to set the primary keys on the client side, instead of inserting values without primary keys and then fetching them back onto the client. Aside from anything else, it means you can easily make parent/child relationships and have the keys all in place before you do any inserts, which makes batching them simpler.

What's the Hi/Lo algorithm?

69 questions
3
votes
2 answers

HiLo or identity?

Just wanted to get some opinions on primary keys - would it be better to use identity/sequence numbers or use a HiLo strategy (query for the high value and increment the low value on the app itself)?
Otávio Décio
  • 73,752
  • 17
  • 161
  • 228
3
votes
1 answer

Spring Boot Hibernate not picking up use-new-id-generator-mappings property

I'm upgrading my project to Spring Boot 2.1.18 that uses Hibernate 5.3.18. Previously, my entity looked like thus and would use the SequenceHiLoGenerator: @Entity @Table(name = "group_link") @SequenceGenerator(name = "group_link_seq", sequenceName =…
AHungerArtist
  • 9,332
  • 17
  • 73
  • 109
3
votes
3 answers

Running out of NHibernate HiLo-ids resulting in negative numbers

We're running an ASP.NET database application which uses HiLo to generate ids for entities. On top of this application, we have several websites using the same database. What we're seeing is that we run out of ids and the ID-column becomes a…
Pieter
  • 3,339
  • 5
  • 30
  • 63
3
votes
1 answer

NHibernate Hi-Lo

Yo Quick q: are Nhibernate HiLo ids unique accross the DB? The reason I ask is that we have multiple entities which have an image associated with them. On the client - I am simply storing these images in a folder using the enity ID as the name - am…
user156888
3
votes
0 answers

How does Hibernate HiLo algorithm guarantee ID uniqueness for clustered applications?

Hibernate HiLo algorithm is very well explained in this post - What's the Hi/Lo algorithm? But I am not clear with how does it guarantee ID uniqueness for clustered application. For example, if Hi number is 35 and if two clients try to increment…
Daddy
  • 61
  • 2
3
votes
1 answer

Fluent NHibernate — specify table/column names when using HiLo generator

Yes, nit-picky is a good way to describe this... ;) Does anyone know if you can specify the table and/or column names to use HiLo using Fluent NHibernate? Currently the schema export creates this... create table hibernate_unique_key ( next_hi…
Sean Gough
  • 1,721
  • 3
  • 26
  • 47
2
votes
0 answers

Is HiLo more efficient than autoincrement bigint? (and another questions)

I have some questions about HiLo. I have seen in examples that if I use HiLo, in the database it is created sequence files to asign the ID. I am wondering what happen if one client use for example HiLo but another client doesn't use it. Is it…
Álvaro García
  • 18,114
  • 30
  • 102
  • 193
2
votes
2 answers

NHibernate HiLo doesn't generate ID on objects in collections

I'm using NHibernate and HiLo strategy and my problem is that IDs of objects in collections are not generated on Session.Save() (only on Transaction.Commit()). For example: ImageGallery imageGallery =…
mlaen
  • 53
  • 5
2
votes
2 answers

NHibernate Hi/Lo - gaps in ids

Scenario: Hi/Lo is initialized for MyEntity with Lo 100 The table is empty. Two sessions with different connections have both inserted three items. TableIds 1 2 3 100 101 102 If a third one comes in at a later time and inserts three…
Daniel
  • 8,133
  • 5
  • 36
  • 51
2
votes
2 answers

How do I set a hibernate sequence manually in mysql?

I'm doing some data migration after some data model refactoring and I'm taking a couple tables with composite primary keys and combining them into a larger table and giving it its own unique primary key. At this point, I've written some SQL to copy…
lakemalcom
  • 1,016
  • 1
  • 8
  • 17
2
votes
2 answers

How to enable the Hibernate HiLo entity identifier optimizer strategy

I'm initializing Hibernate without any XML by something like org.hibernate.SessionFactory sessionFactory = new org.hibernate.cfg.Configuration(). .setProperty(...) .setProperty(...) ... .buildSessionFactory(); My classes use an…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
2
votes
3 answers

NHibernate HiLo generation and SQL 2005/8 Schemas

I have an issue on my hands that I've spent several days searching for an answer to no avail... We're using HiLo Id generation, and everything seems to be working fine, as long as the entity table is in the same schema as the hibernate_unique_key…
Kirk Clawson
2
votes
2 answers

Nhibernate id’s with sequential one step incremented id’s (alternatives to HiLo)

How do I instruct Nhibernate to generate sequential one step primary keys, like the sql generated ones? The current HiLo algorithm generates keys like 4001 then 5010, 6089 etc. I understand that this is to manage multiple app servers etc. But I…
Quintin Par
  • 15,862
  • 27
  • 93
  • 146
2
votes
2 answers

When using a HiLo ID generation strategy, what types should be used to hold Ids?

I'm asking this from a c#/NHibnernate perspective, but it's generally applicable. The concern is that the HiLo strategy goes though id's pretty quickly, and for example a low record-count table (Such as Users) is sharing from the same set of id's…
UpTheCreek
  • 31,444
  • 34
  • 152
  • 221
2
votes
1 answer

What datatype should be used for the Id primary key columns using a hilo generator and sql server?

If I am using a hilo generator with nhibernate, what should the datatype for my id column be? int or bigint?
Michael Hedgpeth
  • 7,732
  • 10
  • 47
  • 66