-->
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: MySql DATETIME doesn't populate time in java.util.Date
PostPosted: Mon Aug 01, 2005 12:38 pm 
Newbie

Joined: Mon Aug 01, 2005 12:31 pm
Posts: 2
Hello

Possibly a quick question.

I am mapping a MySql datetime field to a java.util.Date field but only the date part is being set, I lose all time information from the DB.

My field is:

Name: due
Datatype: DATETIME

My mapping line is:

<property name="dateDue" type="date" column="due"/>


I have two rows. The due field is set to:

2005-08-02 10:22:00
2005-08-02 10:23:00

So I end up with java.util.Date objects, both with the date as 2005-08-02 but the time part is blank. If I print dueDate.getTime() I end up with:

1122850800000
1122850800000

So the milliseconds is the same for both objects.

Can anyone help me please?

MySql: 4.1.9
Hibernate: 3.0.5
MySql Driver: MySql connector 3.0.14

Many thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 12:44 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Map your DateTime column to java.sql.Timestamp as follows:

<property name="dateDue" type="java.sql.Timestamp" column="due"/>

You will also need to change the data type in your class files accordingly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 1:02 pm 
Newbie

Joined: Mon Aug 01, 2005 12:31 pm
Posts: 2
Super, that worked, thankyou.

Seems strange that DATETIME doesnt include a time :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 26, 2006 12:57 pm 
Newbie

Joined: Sun Nov 26, 2006 12:53 pm
Posts: 13
jaikiran wrote:
Map your DateTime column to java.sql.Timestamp as follows:

<property name="dateDue" type="java.sql.Timestamp" column="due"/>

You will also need to change the data type in your class files accordingly.



You can also use java.util.Calendar as mapping type. Each Sun document insist upon the fact that java.util.Date is... out of date ;)


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.