1

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 Table:

PatientRecord (table)
 - Id 

To retain data integrity, I just use the existing Patients.Id as the new PatientRecord.Id:

insert into PatientRecord (Id) 
select Id from Patients

And create an EntityId entry:

insert into EntityId values ('PatientRecord', ??)

where ?? is the next hi value. What value should I use here? By default, initializing the column would be 1. Do I just use that, or should I use something like select MAX(Id) from PatientRecord?

moribvndvs
  • 42,191
  • 11
  • 135
  • 149
  • If you're using NHibernate 3.3 or later, you can also use the "Enhanced ID generators" with one of the "pooled" optimizers, for a more straightforward mapping between the generators stored value and the next usable identifier. – Oskar Berggren Sep 13 '12 at 17:33
  • @OskarBerggren Thanks for the suggestion. Could you point out any decent documentation on pooled enhanced ID generators? – moribvndvs Sep 17 '12 at 18:06
  • It works basically the same as in Hibernate: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html#mapping-declaration-id-enhanced You can also look for examples in the NHibernate.Test source code: https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate.Test/IdGen/Enhanced/ You would pick Table or Sequence based on database construct (but Sequence will revert to table if necessary), then pick optimizer based on how you want to handle the contents. "pooled-lo" is IMHO closest to a "natural human understanding". – Oskar Berggren Sep 20 '12 at 14:33

1 Answers1

1

The next_hi is like a session key used for multiplication for generating the identity (id) so you can insert whatever you want like for example 1 or 2 or 10 each user increments the next_hi and with it it generates all identitys until some max value and then again asks for another next_hi by incrementing it... with this strategy all identity's are unique ... and they can be generated locally

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

http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-explained.html

Community
  • 1
  • 1
visar_uruqi
  • 2,484
  • 1
  • 23
  • 20