NHibernate 3.2忽略实体名称

时间:2013-01-12 13:18:01

标签: nhibernate

我正在使用NHibernate 3.2并且为同一个类映射了两个表,在映射中指定了“entity-name”。麻烦的是,当我在ISession中使用该方法来指示实体名称NHibernate坚持代表他们自己扣除时,忽略了我的规范。

这是我的单元测试中的代码:

public class Cliente
{
    public virtual Guid UID { get; set; }
    public virtual long Revisao { get; set; }
    public virtual string Nome { get; set; }
    public virtual DateTime DataNascimento { get; set; }
}

  <class name="Cliente">
    <id name="UID">
      <generator class="guid"/>
    </id>
    <version name="Revisao" />
    <property name="Nome" />
    <property name="DataNascimento" />
  </class>

  <class name="Cliente" entity-name="ClienteAudit" schema="audit">
    <composite-id>
        <key-property name="UID" />
        <key-property name="Revisao" />
    </composite-id>
    <property name="Nome" />
    <property name="DataNascimento" />
  </class>   

 var cliente = new Cliente {DataNascimento = DateTime.Parse("1988/07/09"), Nome = "Heber Senger"};
        using (var ss = sf.OpenSession())
        {
            ss.Save("Cliente", cliente);
            ss.Flush();
        }

NHibernate坚持将实体保存为“ClienteAudit”(我在监听器和表中验证),并明确告知实体名称为“Cliente”。

我试试: - 在Cliente映射中指定实体名称; - 在方法保存中忽略名称,让NHibernate自由发现名称,再次暗示“ClienteAudit”; - 现在我研究SessionImpl的内部代码等等。

如果有人能提供帮助就会很棒。感谢。

1 个答案:

答案 0 :(得分:0)

所有工作都需要进行两项更改:

  1. 版本属性的默认类型为int且NOT long;
  2. 最重要的:在HBM中显示实体名称时,保存方法中指定的名称是类的全名。
  3. 顺便说一句,谢谢!