-->
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.  [ 1 post ] 
Author Message
 Post subject: Saving Only Date Part of DateTime Property
PostPosted: Tue Jun 06, 2006 12:19 am 
Newbie

Joined: Thu Jun 01, 2006 1:02 pm
Posts: 1
Hi,

I'm using NHibernate v1.0.2.0, SQL Server 2000, .Net 1.1 and VB.NET.

I'm trying to save just the date part of a DateTime property to a DATETIME database column. From what I've read, it sounds like I should be able to use the NHibernate type = date (as opposed to DateTime or timestamp) to save just the date part of the property. Is this assumption correct? If so, can someone help me with the setup?

VB.NET Property definition
Code:
Private _LastLogon As DateTime

Public Property LastLogon() As DateTime
  Get
    Return _LastLogon
  End Get
  Set(ByVal Value As DateTime)
    If Value <> _LastLogon Then
      _LastLogon = Value
      _IsChanged = True
    End If
  End Set
End Property


Mapping file
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="com.v1s.v1web.entities.User, V1WebBizEntities" table="users_vb">
<id name="LogonID" column="LogonID" type="String">
<generator class="assigned" />
</id>
<property name="Name" column="Name" type="String" />
<property name="Password" column="Password" type="String" />
<property name="EmailAddress" column="EmailAddress" type="String" />
[b]<property name="LastLogon" column="LastLogon" type="Date" />[/b]
<property name="ProblemUser" column="ProblemUser" type="Boolean" />
</class>
</hibernate-mapping>


I traced through the Persister.cs code to the point where the field values get bound to the SQL data parameters. When NullSafeSet is called for the NHibernate.Type.DateType type, the parameter is set to the entity's field value without truncating the time.

From DateType.cs
Code:
parm.DbType = DbType.Date;
parm.Value = value;


I would have expected some kind of "massaging" of the value to truncate the time portion (the inverse of what is done in DateTimeType.cs)

From DateTimeType.cs
Code:
DateTime dateValue = ( DateTime ) value;
parm.Value = new DateTime( dateValue.Year, dateValue.Month, dateValue.Day, dateValue.Hour, dateValue.Minute, dateValue.Second );


Am I completely offbase here in thinking that the date type should truncate the time portion?

Thanks


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

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.