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?
Asked
Active
Viewed 2,559 times
2 Answers
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?
-
`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 -
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