These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem with .NET 2.0 Nullables and ICriterion expressions
PostPosted: Thu Sep 28, 2006 5:42 am 
Newbie

Joined: Fri Apr 21, 2006 5:33 pm
Posts: 12
Hi again,

I've got a small issue using .NET Nullable types in ICriteria expressions. I have the following class (I've removed the ID/Version stuff for brevity):

Code:
Public Class Order
    Private m_OrderDate As Nullable(Of DateTime)
    Public Overridable Property OrderDate() As Nullable(Of DateTime)
        Get
            Return m_OrderDate
        End Get
        Friend Set(ByVal value As Nullable(Of DateTime))
            m_OrderDate = value
        End Set
    End Property
End Class


The mapping file:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Northwind.Order, Northwind" table="`Order`" optimistic-lock="all" dynamic-update="true" dynamic-insert="false" select-before-update="true" lazy="true">
    <id name="ID" column="`ID`" type="Integer">
      <generator class="assigned" />
    </id>
    <version name="Version" column="`VERSION`" type="Int64" unsaved-value="-1" />
    <property name="OrderDate" column="`OrderDate`" type="DateTime" />
  </class>
</hibernate-mapping>


So here's the interesting bit. I can load the object (using ISession.get) from the database without a problem.

However, if I try to do a filtered search with expressions (using ICriteria.List), I get the following exception:

Quote:
A first chance exception of type 'Northwind.ApplicationException' occurred in Northwind.dll
Northwind.vshost.exe Error: 0 : Northwind.ApplicationException: There was a problem when loading [Northwind.Order] ---> NHibernate.ADOException: Unable to perform find ---> System.InvalidCastException: Specified cast is not valid.
at NHibernate.Type.DateTimeType.Set(IDbCommand st, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object value, Int32 index, ISessionImplementor session)
at NHibernate.Loader.Loader.BindPositionalParameters(IDbCommand st, QueryParameters queryParameters, Int32 start, ISessionImplementor session)
at NHibernate.Loader.Loader.PrepareQueryCommand(SqlString sqlString, QueryParameters parameters, Boolean scroll, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List()


I've read various posts about using the Nullables package, but I can't do that - my domain objects need to use standard .NET datatypes.

Does anyone have any ideas?
TIA.
Vij


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 9:30 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Nullable types are not the problem, probably the column is not of date/time type.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 5:21 am 
Newbie

Joined: Fri Apr 21, 2006 5:33 pm
Posts: 12
Thanks Sergey,

I checked my database table, and the OrderDate column is definitely DateTime.

The strange thing is that if I use ISession.get(), everything is fine - I can edit the date and save it back to the database. It's the ICriteria.List() that fails.

Any other ideas? Could it be a problem with .NET Nullables within the NHibernate code?

Has anyone else been successful at using a Nullable DateTime in an ICriterion?

Vij


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 7:27 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Can you report this to JIRA with a test case, please?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.