-->
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.  [ 6 posts ] 
Author Message
 Post subject: little help with Hibernate and MySQL data types needed
PostPosted: Thu Jan 25, 2007 5:53 am 
Newbie

Joined: Thu Jan 25, 2007 5:31 am
Posts: 8
Hello guys :)
I'm kinda new in hibernate and I experience some little problems with it
however this is because of my lack of knowledge :)
but the problem that badgers me is the differences between the data types
so I'm using hibernate 3.2.1
and MySQL 5.0 on FreeBSD
I have a table looking like this
describe the_table;
+------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------------+------+-----+---------+----------------+
...
...
| bse_date | datetime | YES | | NULL | |
...
...

the documentation of MySQL says that this type "datetime" reflects the java.sql.Timestamp
so I've mapped it like this

Code:
private Timestamp bseDate;


I have some values in this table and I wanna make some updates

when I select some rows I can see this column showing me date and time like this:
2007-01-25 11:31:42
this is correct
after I do this kind of update:
Code:
Query updateQuery = session.createQuery("update TheTable t set t.BseDate = :bseDate where t.Idr = :id");
Timestamp ts = new Timestamp(new Date().getTime());
updateQuery.setDate("bseDate", ts);
updateQuery.setLong("id", 2824198);
updateQuery.executeUpdate();
session.flush();

and when I select the updated row I get this date
2007-01-25 00:00:00

the hours, minutes and seconds are gone
this is bad for me :)
how can I play with the types to get this working correct ?

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 6:15 am 
Beginner
Beginner

Joined: Thu Aug 04, 2005 5:06 am
Posts: 31
Location: Bedford, UK
Have you mapped to type java.sql.Timestamp ?

Try setting to new Timestamp(System.currentTimeMillis())


cheers,

Mark Dathorne


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 7:14 am 
Newbie

Joined: Thu Jan 25, 2007 5:31 am
Posts: 8
No, this does not work too
may be I should say that I do not want to take the current hour:minute:second
I get a String from another place
and parse it to Date and then update the database
so the date my be yesterday or even older
I need to update the table using given object of type java.util.Date


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 7:27 am 
Newbie

Joined: Thu Jan 25, 2007 5:31 am
Posts: 8
OK it works now
using setTimestamp() instead of using setDate()
thanks to Georgi Georgiev! :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 7:29 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Though I am not sure but it seems that problems lies with the way string is being parsed to date.

if you use new Date(year, month, date) to create a date then it will set the hour, minute and second to 0.

Post your parsing code, may be someone can point out the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 7:35 am 
Newbie

Joined: Thu Jan 25, 2007 5:31 am
Posts: 8
No, the date is parsed correctly for sure
I just was wrong using setDate();
now everything is fine using setTimestamp()
thank you anyway :)


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