Reputation: 316
I am trying to insert a object but it throwns me the Error: dehydrating property value for FrancosPoS.DBMapping.order.obs
I've looked here for
NHibernate: Error dehydrating property - What the heck is this? ,
NHibernate - Error dehydrating property value and
Receiving Index Out of Range with NHibernate, but none of them worked.
I have checked and re-checked my mapping to multiple columns declarations but did not find any problem.
My clue is that the problem has something to do with the bigint on the MySQL database and the identity generator
. When I change it to increment
the dehydrating error goes away and the Index out of range
exception appears.
Additionally, this is happening on the Session Save
call. With the increment
generator, the error happens at commit
time.
Here is my order xml mapping:
<?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>
And the cs class:
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; }
}
Here is the inner exception followed by the stack trace:
"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)
Upvotes: 2
Views: 11096
Reputation: 316
I have found the solution by trial and error, commenting all the mappings on the xml file that could be null in the database and I've got stuck in the bakingTime
property:
<property name="bakingTime">
<column name="date" sql-type="datetime" not-null="false" />
</property>
As I guessed (and others suggested on the other posts) the mapping is wrong. By a copy-paste problem [:P] the column name of bakingTime
refers to the date
column, not to itself!!!
So, this should be:
<property name="bakingTime">
<column name="bakingTime" sql-type="datetime" not-null="false" />
</property>
Also, this post is still valuable, even though is not so new:
"NHibernate Nullable DateTime Issues - Ayende"
Upvotes: 3
Reputation: 5629
Funny naming scheme for .Net code, but you shouldn't need both <id> and <property> for idOrder.
Upvotes: 1