-->
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: Querying MySql timestamp field in HQL
PostPosted: Wed Apr 04, 2007 6:50 am 
Newbie

Joined: Wed Apr 04, 2007 6:19 am
Posts: 3
Hi,
I am facing a problem in querying timstamp field from the database, here are the steps i am following,

1) I have created a table in MySql having a field of type as TIMESTAMP.
a) The data inserted to this filed is of type Calendar,
by converting the java.util.Date into Calendar

2) In hibernate mapping files, i have given as
<property name="user_timestmap" column="user_timestamp"
type="java.util.Calendar" />
a) I even tried giving java.util.Date
b) I even tried not giving the type at all

3) The setters and getters are of type java.util.Calendar

4) I am trying to query the table using 3 different ways
a) select max(u.user_timestamp) from user as u
---> this is working fine (but i dont want this)
b) select u from user as u where u.user_timestamp between 'ca' and 'cb'
---> ca is the Calendar instance with starttime
---> cb is the Calendar instance with endtime
(This results in 0 rows)
c) select u from user as u where u.user_timestamp > 'cd'
---> cd is the Calendar instance with the starttime, records which have
timestamp greater than that should be queried
(This results in 0 rows)


Please help me out in querying these timestamps


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 9:02 am 
Regular
Regular

Joined: Mon Jun 12, 2006 5:33 am
Posts: 63
HI aruna_shankar03,

use timestamp type instead. So your mapping will be:
Code:
<property name="user_timestmap" type="timestamp" column="user_timestamp" />


Chucky
---------
Don't forget to rate if this helps


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 12:51 am 
Newbie

Joined: Wed Apr 04, 2007 6:19 am
Posts: 3
Hi Chucky,

Thank You for your suggestion. But,

1) I tried giving the hibenate type = timestamp as u suggested
2) Changed the setters and getters into java.util.Date()
3) Sql field remained the same..... TIMESTAMP (I am using MySql as
database)

Still it gives me the same result (0 rows)

Is there any problem in querying timestamp using MySql as such?

Please help me out


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 1:20 am 
Newbie

Joined: Wed Apr 04, 2007 6:19 am
Posts: 3
Hip Hip Hurry !!!!!!!!!

I solved it :)


Steps folloed to solve the problem

1) Make the hql as Named query in the hbm.xml file with ? for the
calendar field
2) In the program i just called the
session.getNamedQuery("query name").setCalendar(0,cd);

[Note : ]
--> Can use any of the Calendar,Date,timestamp as hibernate type in
the hbm file when we use timestmap or Date field in the sql.
--> When we use complex datatypes other than int and String, better to
use NamedQuery as it associated the input variables to the
hibernate types automatically.


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.