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?
+3
A:
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
2009-10-19 07:37:53
What about nhibernate increment as below? What are disadvantages or advantages?<id name="Id" column="ID" type="Decimal"> <generator class="increment" /></id>
NetSide
2009-10-20 08:00:04
`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
2009-10-20 08:41:38
Thanks Stefan, I am using seqhilo now , but it increments id's not one by one. is it normal?<id name="Id" column="ID" type="decimal"> <generator class="seqhilo"> <param name="sequence">SEQUENCE_BUNDLE</param> </generator> </id>
NetSide
2009-10-21 12:48:11
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
2009-10-21 14:20:13
thanks again Stefan, Thats why it works more efficient :)
NetSide
2009-10-24 19:24:30
do you know a link about seqhilo properties for example "max_lo"?I'd like to know about the meanings of these properties?
NetSide
2009-10-24 19:35:09