-->
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.  [ 5 posts ] 
Author Message
 Post subject: DateTime type not being saved correctly.
PostPosted: Mon Feb 27, 2006 4:54 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Hi,

I have a class with a property of DateTime type. in my MSSQL, the column type is also DateTime. Everything worked fine until I try to order by that property. It only store the date, not the time (says 12:00:00 for every entry).

when I check my property in the debugger, it says the correct date AND time but not in the DB. Any idea?

Here is my mapping doc:
<class name="Com.Progmatik.OSWeblog.BlogContent, Com.Progmatik.OSWeblog.ObjectsModel" table="BlogContent" discriminator-value="BlogContent">
<id name="IdBlogContent" unsaved-value="0" access="nosetter.camelcase-underscore">
<generator class="native" />
</id>
<discriminator column="SubClass" type="String" />
<!--<version name="Version" column="Version" unsaved-value="0" />-->
<property name="Content" column="BlogContent" />
<property name="DatePosted" />
<property name="Title" />
</class>
</hibernate-mapping>



Here is my class:

public class BlogContent
{
private DateTime _datePosted;

public DateTime DatePosted
{
get { return this._datePosted; }
set { this._datePosted = value; }
}
}


Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 6:37 pm 
Regular
Regular

Joined: Wed Feb 15, 2006 9:09 pm
Posts: 76
Try forcing the underlying table type in your entity map:

<property name="DatePosted" type="timestamp"/>

See 1.2.2 The Mapping File. If you scroll down to the third paragraph after the fourth code block, you'll see this:

Quote:
In some cases this automatic detection (using Reflection on the Java class) might not have the default you expect or need. This is the case with the date property. Hibernate can't know if the property (which is of java.util.Date) should map to a SQL date, timestamp, or time column. We preserve full date and time information by mapping the property with a timestamp converter.


In your class you're using DateTime (and a totally different language and platform :), but I suspect it's the same issue.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 7:38 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Hi there,

Thanks for the quick reply!

I tried it and still the same. Actually, I tried with the property type="timestamp", "date" and "time" and I still get 12:00:00 AM in all cases.

what else could it be?

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 28, 2006 6:12 am 
Regular
Regular

Joined: Tue Mar 15, 2005 12:38 pm
Posts: 73
Location: Bucharest
I'm using "DateTime" (or "System.DateTime") and works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 28, 2006 10:21 am 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Geez! My Fault!!!

on one place, I had myObject.DatePosted = DateTime.Now;

and somewhere else,

I had myObject.DatePosted = new DateTime((int)2005, (int)05, (int)05);
which would set the time to 12:00:00AM !!

Can't believe I lost 10h on this!!!

Thanks anyways


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