Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Identity fields

Getting started with NHibernate

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

like image 699
user366312 Avatar asked Jun 19 '09 21:06

user366312


People also ask

What is the difference between NHibernate and fluent NHibernate?

Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.

What is the difference between NHibernate and Entity Framework?

Difference between NHibernate and Entity FrameworkEntity framework requires additional connections to handle databases other than MSSQL, which nHibernate provides. In terms of data loading, SQL generation, custom column types, custom collections, and so on, NHibernate can be modified.

Is NHibernate an ORM?

NHibernate is a port of Hibernate from Java, one of the oldest and most respected Object-Relational Mappers (ORMs).


2 Answers

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.

like image 84
Mark Rogers Avatar answered Oct 19 '22 10:10

Mark Rogers


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

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

like image 42
shahkalpesh Avatar answered Oct 19 '22 10:10

shahkalpesh