-->
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: native query in hibernate3
PostPosted: Thu May 20, 2010 10:38 am 
Newbie

Joined: Mon Feb 21, 2005 2:15 pm
Posts: 9
Hello,

I am writing a native query which has some comparisions with dates, and it does not work through hibernate but works on the PL/SQL developer.

My code is as follows :
SQLQuery q = session.createQuery(" select {x.*}, {y.*}, {z.*} from X x, Y y, Z z
where to_char({x}.date, 'mm/dd/yyyy hh24mi') >= to_char(:date, 'mm/dd/yyyy hh24mi') ");

q.addEntity("x", X.class);
q.addEntity("y", Y.class);
q.addEntity("z", Z.class);

if (date != null)
q.setDate("date", date);

List l = q.list();
return l;


The above query does not return the correct resultset because of the way hibernate translates :
to_char({x}.date, 'mm/dd/yyyy hh24mi') >= to_char(:date, 'mm/dd/yyyy hh24mi')

When I tried to to replace the above query with this
select to_char(:date, 'mm/dd/yyyy hh24mi') from dual;
It returns me 05/20/2010 0000
instead of 05/20/2010 1025

Not sure if this is a bug in Hibernate.
The only work around I could think was to format the date in java and pass it to the query.
Has anyone faced this problem before ?

Thanks,
Gayatri


Top
 Profile  
 
 Post subject: Re: native query in hibernate3
PostPosted: Thu May 20, 2010 2:39 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I am not sure this will help... but I think the setDate() is for the date-only part, setTime() for the time-only part and setTimestamp() for complete date + time.


Top
 Profile  
 
 Post subject: Re: native query in hibernate3
PostPosted: Thu May 20, 2010 3:52 pm 
Newbie

Joined: Mon Feb 21, 2005 2:15 pm
Posts: 9
That worked. Thank you.

q.setTimestamp("date", date);

Thanks,
Gayatri


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.