2

I am using Nhibernate for oracle, and I need to increment my primary key value for each insert. Which one is the best way and efficient way? Oracle sequence, Nhinerbate increment or another way?

NetSide
  • 3,849
  • 8
  • 30
  • 41

2 Answers2

2

With oracle, you could use seqhilo, which uses a database sequence instead of a separate table. You get the advantage of hilo (key generation in memory, no db roundtrip needed) and sequences (no separate transaction needed) at the same time.

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
  • What about nhibernate increment as below? What are disadvantages or advantages? – NetSide Oct 20 '09 at 08:00
  • `increment` does just increment the id in a static variable. This is fast, but does not work when more then one process (or AppDomain) accesses the database. I wouldn't use it except in a very trivial environment (eg. non client server desktop app). – Stefan Steinegger Oct 20 '09 at 08:41
  • Thanks Stefan, I am using seqhilo now , but it increments id's not one by one. is it normal? SEQUENCE_BUNDLE – NetSide Oct 21 '09 at 12:48
  • This is normal. This is the nature of hilo. It gets a value from the sequence and has a range of numbers free to increment in memory, this way it avoids calling the database for each id. – Stefan Steinegger Oct 21 '09 at 14:20
  • do you know a link about seqhilo properties for example "max_lo"? I'd like to know about the meanings of these properties? – NetSide Oct 24 '09 at 19:35
1

You can use hilo in Nhibernate for generating your Ids (for NHibernate it is most preferable way for managing Ids now).

Community
  • 1
  • 1
Sly
  • 15,046
  • 12
  • 60
  • 89