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.  [ 3 posts ] 
Author Message
 Post subject: DateTime property milliseconds truncated
PostPosted: Fri Jun 15, 2007 6:06 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
NHibernate version: 1.2.0

I just noticed that NHibernate truncates the milliseconds from DateTime properties, even if the underlying database supports them.

The following code in the DateTimeType class implies that this is deliberate:

Code:
public override object Get(IDataReader rs, int index)
{
   DateTime dbValue = Convert.ToDateTime(rs[index]);
   return new DateTime(dbValue.Year, dbValue.Month, dbValue.Day, dbValue.Hour, dbValue.Minute, dbValue.Second);
}

public override void Set(IDbCommand st, object value, int index)
{
   IDataParameter parm = st.Parameters[index] as IDataParameter;
   DateTime dateValue = (DateTime) value;
   parm.Value =
      new DateTime(dateValue.Year, dateValue.Month, dateValue.Day, dateValue.Hour, dateValue.Minute, dateValue.Second);
}


Does anyone know whether was a decision made because some underlying databases may not support the same level of accuracy in DateTime values? It seems a pity to lose DateTime resolution if your DB can support it...

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 6:09 am 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
I think you can use the TimeStamp type also for regular properties (not only for versioning).

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 6:41 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
DateTime has never stored milliseconds, I believe. Use Timestamp, as Martijn said.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.