2

我正在尝试插入一个对象,但它抛出了我Error: dehydrating property value for FrancosPoS.DBMapping.order.obs

我在这里寻找

NHibernate:错误脱水属性 - 这是什么鬼?,

NHibernate - 错误脱水属性值

使用 NHibernate 接收超出范围的索引,但它们都不起作用。

我已经检查并重新检查了我对多列声明的映射,但没有发现任何问题。

我的线索是问题与 MySQL 数据库上的 bigint 和identity generator. 当我将其更改为increment脱水错误消失并Index out of range出现异常。

此外,这发生在Session Save通话中。使用increment生成器,错误有时会发生commit

这是我的订单 xml 映射:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2">
<class name="order" table="`order`" lazy="true" >
<id name="idOrder">
  <generator class="identity" />
</id>
<many-to-one lazy="false" name="employee">
  <column name="idEmployee" sql-type="bigint(20)" not-null="false" />
</many-to-one>
<many-to-one lazy="false" name="customer">
  <column name="idCustomer" sql-type="bigint(20)" not-null="false" />
</many-to-one>
<many-to-one lazy="false" name="address">
  <column name="idAddress" sql-type="bigint(20)" not-null="false" />
</many-to-one>
<property name="date">
  <column name="date" sql-type="datetime" not-null="true" />
</property>
<property name="bakingTime">
  <column name="date" sql-type="datetime" not-null="false" />
</property>
<property name="price">
  <column name="price" sql-type="decimal(8,4)" not-null="true" />
</property>
<property name="cash">
  <column name="cash" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="credit">
  <column name="credit" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="houseNumber">
  <column name="houseNumber" sql-type="bigint(20)" not-null="false" />
</property>
<property name="complement">
  <column name="complement" sql-type="bigint(20)" not-null="false" />
</property>
<property name="obs">
  <column name="obs" sql-type="varchar(350)" not-null="false" />
</property>

<bag name="orderPsi" table="ordPsi" cascade="all" inverse="true">
      <key column="idOrdPastaI" />
      <one-to-many class="ordPsi" />
</bag>
</class>
</hibernate-mapping>

还有cs类:

public partial class order {
    public order() { }
    public virtual long idOrder { get; set; }
    public virtual employee employee { get; set; }
    public virtual customer customer { get; set; }
    public virtual address address { get; set; }
    public virtual System.DateTime date { get; set; }
    public virtual System.Nullable<System.DateTime> bakingTime { get; set; }
    public virtual string price { get; set; }
    public virtual System.Nullable<int> cash { get; set; }
    public virtual System.Nullable<int> credit { get; set; }
    public virtual System.Nullable<long> houseNumber { get; set; }
    public virtual System.Nullable<long> complement { get; set; }
    public virtual string obs { get; set; }
    public virtual IList<ordPsi> orderPsi { get; set; }
}

这是堆栈跟踪后跟的内部异常:

"Parameter index is out of range."
at MySql.Data.MySqlClient.MySqlParameterCollection.CheckIndex(Int32 index)
at MySql.Data.MySqlClient.MySqlParameterCollection.GetParameter(Int32 index)
at System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object value, Int32 index, Boolean[] settable, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, IDbCommand statement, ISessionImplementor session, Int32 index)
4

2 回答 2

3

我通过反复试验找到了解决方案,评论了数据库中可能为空的 xml 文件上的所有映射,并且我陷入了该bakingTime属性:

<property name="bakingTime">
  <column name="date" sql-type="datetime" not-null="false" />
</property>

正如我所猜测的(以及其他帖子中的其他人所建议的),映射是错误的。通过复制粘贴问题 [:P] 的列名bakingTime指的是该date列,而不是它本身!!!

所以,这应该是:

<property name="bakingTime">
  <column name="bakingTime" sql-type="datetime" not-null="false" />
</property>

此外,这篇文章仍然很有价值,即使不是那么新:

“NHibernate Nullable DateTime 问题 - Ayende”

于 2012-11-24T21:44:28.403 回答
1

.Net 代码的有趣命名方案,但对于 idOrder,您不应该同时需要 <id> 和 <property>。

于 2012-11-24T13:34:22.067 回答