-->
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.  [ 7 posts ] 
Author Message
 Post subject: how to compare date of Oracle DB via Hibernate?
PostPosted: Thu Apr 08, 2004 5:47 am 
Newbie

Joined: Tue Nov 11, 2003 8:22 am
Posts: 5
Dear All,

Can anyone share his/her experience of how to compare date of Oracle
DB thru Hibernate query statements? I always have the sql exceptiom
ORA-01861, literal does not match format string.

My query string just likes "select ... from ... where ... between '2004-01-01'
and '2004-04-01'.... ".

I use Hibernate 2.1.2 and Oracle 9i.

any suggestions?

Jun-Liang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 5:52 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You have to use the Oracle todate() function in the where clause of HQL if you work with strings. Why not have a java.util.Date object and bind it as a parameter?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 12:11 am 
Newbie

Joined: Tue Nov 11, 2003 8:22 am
Posts: 5
christian wrote:
You have to use the Oracle todate() function in the where clause of HQL if you work with strings. Why not have a java.util.Date object and bind it as a parameter?



Thanks for your help!

But could you elaborate the sentence "Why not have a java.util.Date object and bind it as a parameter?" My real situation is I need to query
from several tables and one of where clause including statements about
comparing date in Oracle DB and considering future of portability of code
we think it is better stick to Hibernate and not using any particular native db
functions. Any comments? or simple example?


Jun-Liang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 12:18 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the documentation about parameter binding. You can even read any JDBC documentation, its the same.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 2:07 am 
Newbie

Joined: Tue Nov 11, 2003 8:22 am
Posts: 5
christian wrote:
Read the documentation about parameter binding. You can even read any JDBC documentation, its the same.


I got it! Thanks!

Jun-Liang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 5:40 am 
Newbie

Joined: Fri Apr 09, 2004 9:28 am
Posts: 2
Location: Brussels, Belgium
Would it be acceptable to manually set the NLS_DATE_FORMAT environment constant with a jdbc statement like this one in your case:

Alter Session set NLS_DATE_FORMAT = 'YYYY-DD-MM'

prior to any query (needed only once) ?

Or would it be more advisable to set it directly in the database server itself ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 11:52 am 
Newbie

Joined: Tue Jun 01, 2004 8:06 pm
Posts: 9
Location: Hamilton, Ontario, Canada
We set our NLS_DATE_FORMAT on the server. It's much less of a hassle, in case you forget to code, etc. And it gives you one central location to change it.


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