Implementación del generador de id HiLo NHibernate

I would like to use "hilo" generator but there is no any complete example how to create "specific" table as NH documentation says, and which values pass to it. The following code fragments taken from NH tutorial

public class Cat
{
    private Int64 id;
    private string name;
    private char sex;
    private float weight;

    public Cat()
    {}

    public virtual Int64 Id
    {
        get { return id; }
        set { id = value; }
    }
    ....
}

Mapper

<hibernate-mapping ...>
<class name="Cat" table="Cat">
  <id name="Id" >
    <column name="CatId" sql-type="Int64" not-null="true"/>
    <generator class="hilo"/>
  </id>
  <property name="Name">
    <column name="Name" length="16" not-null="true" />
  </property>
  ....
</class>
</hibernate-mapping>

DB table "Cat" CatId bigint NOT NULL Name varchar(16) NOT NULL Sex char(1) NULL Weight real NULL doesn't create anything in the database by default.

Parameters in the "id" node

    <param name="table">hi_value</param>
    <param name="column">next_value</param>
    <param name="max_lo">100</param>

gives "Invalid object name 'hi_value'" error message, without them I'm getting "Invalid object name 'hibernate_unique_key'."

Cuid.Comb that is shown in their tutorial works good but gives 99.12% of fragmentation when I added in a loop 20K cat objects. Can somebody point me to an example of "hilo" implementation or give a tip what I'm missing?

Gracias.

preguntado el 08 de noviembre de 11 a las 15:11

2 Respuestas

Este patrón de solución solved my problem. It's fairly simple, don't know why on nhibernate site there is no tiny example like that.

contestado el 23 de mayo de 17 a las 13:05

Puede que te estés encontrando NH-2687.

respondido 08 nov., 11:21

IIRC it's not an issue, it's closed, and I have to implement it by my own based on that example Fabio Maulo provided with the link? - Máxima

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.