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
505
votes
5 answers

What's the Hi/Lo algorithm?

What's the Hi/Lo algorithm? I've found this in the NHibernate documentation (it's one method to generate unique keys, section 5.1.4.2), but I haven't found a good explanation of how it works. I know that Nhibernate handles it, and I don't need to…
DiegoCofre
  • 5,053
  • 3
  • 17
  • 6
148
votes
6 answers

Hibernate, @SequenceGenerator and allocationSize

We all know the default behaviour of Hibernate when using @SequenceGenerator - it increases real database sequence by one, multiple this value by 50 (default allocationSize value) - and then uses this value as entity ID. This is incorrect behaviour…
G. Demecki
  • 10,145
  • 3
  • 58
  • 58
17
votes
5 answers

HiLO for the Entity Framework

Has anyone implemented a HiLO key generator for the Entity Framework. Read more about HiLo here: I recommend that you read http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-explained.html for a detailed explanation of the downsides of…
Martin Nyborg
  • 171
  • 1
  • 3
15
votes
5 answers

Is there a practical way of migrating from identity columns to hilo keys?

I work with a database that depends heavily on identity columns. However as we have now moved all applications over to NHibernate I wanted to look into using HiLo as seems to be recommended with NHibernate. Are there any strategies to do this, or…
Jack Ryan
  • 8,396
  • 4
  • 37
  • 76
11
votes
1 answer

What's a good MaxLo value for the HiLo algorithm?

In my current design, I have HiLo setup to have a MaxLo of 1000. Is this being excessive? Could I reduce this number to something like 100 and still be ok? public class HiLoConvention : IIdConvention { public void Apply(IIdentityInstance…
rebelliard
  • 9,592
  • 6
  • 47
  • 80
10
votes
1 answer

Error with hilo in NHibernate - "could not read a hi value - you need to populate the table"

I've genereated a schema for my (SQL 2005) db using SchemaExport, and it's created a table CREATE TABLE [dbo].[hibernate_unique_key]( [next_hi] [int] NULL ) ON [PRIMARY] When I try to add an entity, I get the error "could not read a hi value -…
mcintyre321
  • 12,996
  • 8
  • 66
  • 103
9
votes
0 answers

Hibernate pooled vs pooled-lo id generator

This article (https://vladmihalcea.com/hibernate-hidden-gem-the-pooled-lo-optimizer/) gives a good explanation on the differences for the hilo, pooled and pooled-lo optimizers for sequence generators. It also explains that since hibernate 5, pooled…
len
  • 426
  • 3
  • 11
9
votes
2 answers

NHibernate HiLo - new column per entity and HiLo catches

I'm currently using the hilo id generator for my classes but have just been using the minimal of settings eg ... But should I really…
Gareth
  • 2,061
  • 2
  • 17
  • 22
8
votes
2 answers

What are all the NHibernate HiLo generator params?

I've seen some docs by Fabio Maulo that shows the following params: hi_value next_value …
Mike Scott
  • 12,274
  • 8
  • 40
  • 53
8
votes
5 answers

Once a HiLo is in use, what happens if you change the capacity (maximum Lo)?

If I start using a HiLo generator to assign ID's for a table, and then decide to increase or decrease the capacity (i.e. the maximum 'lo' value), will this cause collisions with the already-assigned ID's? I'm just wondering if I need to put a big…
Jon M
  • 11,669
  • 3
  • 41
  • 47
8
votes
1 answer

NHibernate and hilo generator: how to design key-tables?

I'm about to switch some of my entities from identity to hilo id-generator. I'm don't have a clue how the tables holding the next-high values should be designed. should I use a single table for all entities, or for a group of related…
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
6
votes
1 answer

Switch from nHibernate HiLo to GUID

Is it possible to switch from HiLo to GUID.comb? As far as I can tell, the latter combines the advantage of HiLo, namely managing Ids client-side instead of needing a call to the DB for getting a new Id, with the advantage that it's impossible to…
Pieter
  • 3,339
  • 5
  • 30
  • 63
5
votes
1 answer

Hibernate Sequence Generator is not Consistent

I have a table with promotion id annotated as @SequenceGenerator(name="GEN_PROMID", sequenceName="SEQ_PROMOTIONID", allocationSize=1) @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="GEN_PROMID") @Column(name="PROMOTIONID") private…
abhihello123
  • 1,668
  • 1
  • 22
  • 38
5
votes
1 answer

DDD and MongoDB: Is it okay to let Mongo create ObjectIDs?

According to DDD (Blue book, Evans) a Factory has the responsibility to create an Aggregate Root in a valid state. Does this mean it should be able to create the technical id (objectId in mongoDB world) as well as the domain id? On the one hand,…
Geert-Jan
  • 18,623
  • 16
  • 75
  • 137
4
votes
2 answers

HiLo vs Identity?

This is the same question as: HiLo or identity? Let's take the database of this site as an example. Lets say that the site has the following tables: Posts. Votes. Comments. What is the best strategy to use for it: Identity - which is more…
Fitzchak Yitzchaki
  • 9,095
  • 12
  • 56
  • 96
1
2 3 4 5