I have a SQL DB column of type float that's nullable, and want to map it to a class. Below is my mapping file and the class I'm trying to map to:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="WaterTrax.WTX.WTXObjectModel.Measurements.DWFacSiteMsrmtData, WTXObjectModel" table="tDWFacSiteMsrmtData" proxy="WaterTrax.WTX.WTXObjectModel.Measurements.DWFacSiteMsrmtData, WTXObjectModel">
<id name="id" column="MsrmtDataID" unsaved-value="0">
<generator class="native" />
</id>
...
<property name="detectLimit" column="DetectLimit" not-null="false" type="Nullables.NullableDouble, Nullables"/>
...
</class>
</hibernate-mapping>
public class DWFacSiteMsrmtData
{
private int m_id=0;
...
private Nullables.NullableDouble m_detectLimit;
...
public virtual Nullables.NullableDouble detectLimit
{
get{return m_detectLimit;}
set{m_detectLimit = value;}
}
...
When I run my program and loads a record in which the column DetectLimit is not null, I get an exception shown below:
Quote:
2005-11-04 14:49:51,596 DEBUG [ NHibernate.Impl.BatcherImpl] - Opened Reader, open Readers :1
2005-11-04 14:49:51,596 DEBUG [ NHibernate.Loader.Loader] - processing result set
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.Int32Type] - returning '317723' as column: sSampleID0_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.Int32Type] - returning '1984478' as column: MsrmtDat1_1_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.Int32Type] - returning '277839' as column: DWMsrmtID2_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Loader.Loader] - result row: 317723, 1984478, 277839
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Loader.Loader] - Initializing object from DataReader: 317723
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Loader.Loader] - Hydrating entity: WaterTrax.WTX.WTXObjectModel.Measurements.Sample#317723
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.StringType] - returning '' as column: sDescr0_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.StringType] - returning 'CAHALAN CR' as column: sSampleI3_0_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.StringType] - returning 'OPS' as column: sSampleT6_0_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.DateTimeType] - returning '01/02/2005' as column: sSampleC4_0_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.BooleanType] - returning 'True' as column: sTimePro8_0_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.StringType] - returning '' as column: sComments0_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Type.StringType] - returning 'OPS' as column: sSampleT7_0_
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Loader.Loader] - Initializing object from DataReader: 1984478
2005-11-04 14:49:51,627 DEBUG [ NHibernate.Loader.Loader] - Hydrating entity: WaterTrax.WTX.WTXObjectModel.Measurements.DWFacSiteMsrmtData#1984478
2005-11-04 14:49:52,377 ERROR [ NHibernate.ADOException] - Could not cast the value in field DetectL10_1_ of type Double to the Type SerializableType. Please check to make sure that the mapping is correct and that your DataProvider supports this Data Type.
System.InvalidCastException: Invalid attempt to GetBytes on column 'DetectL10_1_'. The GetBytes function can only be used on columns of type Text, NText, or Image.
at System.Data.SqlClient.SqlDataReader.GetBytes(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length)
at NHibernate.Driver.NHybridDataReader.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferoffset, Int32 length)
at NHibernate.Type.BinaryType.Get(IDataReader rs, Int32 index)
at NHibernate.Type.SerializableType.Get(IDataReader rs, Int32 index)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
2005-11-04 14:49:52,471 DEBUG [Hibernate.Util.ADOExceptionReporter] - SQL Exception
NHibernate.ADOException: Could not cast the value in field DetectL10_1_ of type Double to the Type SerializableType. Please check to make sure that the mapping is correct and that your DataProvider supports this Data Type. ---> System.InvalidCastException: Invalid attempt to GetBytes on column 'DetectL10_1_'. The GetBytes function can only be used on columns of type Text, NText, or Image.
at System.Data.SqlClient.SqlDataReader.GetBytes(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length)
at NHibernate.Driver.NHybridDataReader.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferoffset, Int32 length)
at NHibernate.Type.BinaryType.Get(IDataReader rs, Int32 index)
at NHibernate.Type.SerializableType.Get(IDataReader rs, Int32 index)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
--- End of inner exception stack trace ---
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
at NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
at NHibernate.Loader.Loader.Hydrate(IDataReader rs, Object id, Object obj, ILoadable persister, ISessionImplementor session, String[][] suffixedPropertyColumns)
at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, Key key, String suffix, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session)
at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, String suffix, Key key, LockMode lockMode, Key optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, String[] suffixes, Key[] keys, Object optionalObject, Key optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
Can someone please let me know what's wrong? I'm using release version 1.0.
Thanks.