HiLo NHibernate id generator implementation

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?

Thanks.


This solution solved my problem. It's fairly simple, don't know why on nhibernate site there is no tiny example like that.


您可能会遇到NH-2687。

链接地址: http://www.djcxy.com/p/19124.html

上一篇: 在Azure上的Nhibernate HiLo

下一篇: HiLo NHibernate id生成器实现