views:

386

answers:

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?

+2  A: 

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

Sly
+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
What about nhibernate increment as below? What are disadvantages or advantages?<id name="Id" column="ID" type="Decimal"> <generator class="increment" /></id>
NetSide
`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
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
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
thanks again Stefan, Thats why it works more efficient :)
NetSide
do you know a link about seqhilo properties for example "max_lo"?I'd like to know about the meanings of these properties?
NetSide