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
1
vote
2 answers

Bad Integer 2147483649 (its BIGINT value) error in Postgres

I m using hibernate 3 with hilo key generator and Postgres 9.3.Table column is BIGINT and model class variable is long(java). From back-end no issue but when i try to save from front-end console are showing Bad Integer '2147483649' error. Table…
Suraj
  • 89
  • 1
  • 2
  • 11
1
vote
1 answer

Disable hibernate HiLo Sequence generation

I'm working with Hibernate 4.2.x and I want to disable the HiLo sequence generation - go to the DB (oracle) every time. I added this row to the persistance.xml: And my entity…
TheTufik
  • 105
  • 3
  • 8
1
vote
1 answer

HiLo: how to control Low values

I'm using the HiLo generator in my S#rpArchitecture/NHibernate project and I'm performing a large import batch. I've read somewhere about the possibility to predict the Low values of any new records because they are generated on the client. I figure…
Sandor Drieënhuizen
  • 6,310
  • 5
  • 37
  • 80
1
vote
0 answers

Implementing multi-tenancy in MultipleHiLoPerTableGenerator for Hibernate

I'm trying to create a multi-tenant application with shared schema.We have identified a discriminator field which will help to filter out data base on customers. I'm facing a problem in TableGenerator strategy for generating primary keys for some of…
Rohitdev
  • 866
  • 6
  • 15
1
vote
1 answer

Converting Identity column generator to hilo: what should "next_hi" be initialized to?

I am converting a class that uses the Identity generator to one that uses hilo. I'm also using a single table with distinct row per entity: EntityId (table) - EntityName - NextHigh Old Table: Patients (table) - Id (identity) New…
moribvndvs
  • 42,191
  • 11
  • 135
  • 149
1
vote
1 answer

Are there any gotchas when using HiLo if you need to use replication later?

Currently we only use one database server, and that should be all we need for quite some time. However if I was to convert the database to use HiLo for a POID strategy is there anything I can do now that would make sure I don't have problems with…
joshlrogers
  • 1,136
  • 1
  • 11
  • 20
1
vote
1 answer

Nhibernate HiLo on Azure

Im trying to run create schema in Azure SQL but its failing because im using HiLo generated, Azure SQL requires CLUSTERED INDEX and HiLo table by default doesnt have any index, Anyone has tried HiLo in Azure before? Can anyone point me to to the…
reggieboyYEAH
  • 870
  • 3
  • 11
  • 28
1
vote
3 answers

SQL Server: How to avoid or detect database restore while application is running

It is required to shut down the system I'm working on before the database gets restored. If a customer does not do this, he may run into serious problems, because the in-memory state of the application server does not match the database. It may take…
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
0
votes
1 answer

hibernate HiLo - one table for all entities

I've seen this question NHibernate HiLo - one table for all entities and so I've read http://daniel.wertheim.se/2011/03/08/nhibernate-custom-id-generator/ and i tried to do it on hibernate . hibernate does not check the "where" key in the…
kommradHomer
  • 4,127
  • 5
  • 51
  • 68
0
votes
2 answers

HiLo NHibernate id generator implementation

I would like to use "hilo" generator but there is no any complete example how to create "specific" table as NH documentation says, and which values pass to it. The following code fragments taken from NH tutorial public class Cat { private Int64…
Maxim
  • 4,152
  • 8
  • 50
  • 77
0
votes
0 answers

How can I have multiple ways of generating rawId in spring for an entitiy in hibernate?

I have a situation of doing dual writes where I want to first save the object to a microservice, retrieve the rawId and then save it in the monolith as well. Upon doing application.setId(rawId) I get optimistic locking failure exception . This whole…
0
votes
0 answers

Using HiLo ef Core

class Example { public OwnId Id { get; set; } public string SomeData { get; set; } } class AnotherExample { public OwnId Id { get; set; } public string SomeData { get; set; } } class OwnId { public long Value { get; set;…
0
votes
2 answers

Problem producing a new random number at the end of HiLo guessing game

I'm creating a HiLo guessing game in Java. Everything I have so far works as intended except at the end when I prompt a user to play again, the random number remains the same from the previous game. How do I make it so the code produces a new random…
AWcode
  • 45
  • 4
0
votes
1 answer

TableHiLoGenerator replacement in Hibernate 5

we are migrating from hibernate 4 to hibernate5. We've used "hilo" generator in our project to generate id to many-to-many tables using a table as seguence generator: cw_unique_key
0
votes
1 answer

NHibernate HiLo as long

I will have a table with more than 7 billion rows so I need long for primary key. How to specify the HiLo to use In64 instead of int? Thanks
Luka
  • 4,075
  • 3
  • 35
  • 61