views:

581

answers:

2

http://stackoverflow.com/questions/1020128/getting-started-with-nhibernate

How can I generate identity fields in nHibernate using Hilo algorithm?

+3  A: 

I haven't watched the screencasts yet. But Summer of nHibernate should help you.

I am sorry - I am not answering your original question.

shahkalpesh
Thanks for downvoting. that was expected. I hope the link helps anyway.
shahkalpesh
not the answer but they shouldn't down vote you :)
Yassir
do you know which episode covers this?
Andrew Bullock
+6  A: 

use class="hilo":

<generator class="hilo">

example:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernate__MyClass" assembly="NHibernate__MyClass">
  <class name="MyClass" table="MyClass">
    <id name="Id" type="int" column="ID">
      <generator class="hilo">
    </id>
    <property name="Name">
      <column name="Name" not-null="true" />
    </property>
    <property name="Value">
      <column name="Value" not-null="true" />
    </property>
  </class>
</hibernate-mapping>

I simplified:

<id name="Id">
  <column name="ID" sql-type="int" not-null="true"/>
  <generator class="hilo" />
</id>

to:

<id name="Id" type="int" column="ID">
    <generator class="hilo">
</id>

You could have a syntax error of some sort that is confusing NHibernate.
If you could provide more detail about the code that is executing before the failure or anything else you might think is important, that could speed the rate at which your problem is resolved.

Mark Rogers
I am using SQL Server. Should I create additional tables/columns for hilo?
I.e. does NHib need s additional tables/columns to work with hilo?
Could you provide the code where your doing the insert that fails, I think that might have something to do with the problem. The error message says at some point, your trying to insert a null id.
Mark Rogers
JMSA - Yes it does require an additional table [hibernate_unique_key] for the hilo algorithm but you don't have to create it manually if the sql account has create table privledges.
Steven Lyons