-->
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: Query on date returns no results
PostPosted: Thu Nov 16, 2006 2:06 pm 
Newbie

Joined: Sat Nov 04, 2006 3:43 pm
Posts: 9
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.0.cr4

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="com.hibernate.oracle.Payment" table="PAYMENT_REQUEST">
<id name="id" column="PAYMENT_REQUEST_EID" type="long">
<generator class="increment"/>
</id>
<property name="orderId" type="string" column="ORDER_ID"/>
<property name="orderDate" type="timestamp" column="ORDER_DATE"/>
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Session session = sf.openSession();

Transaction tx = session.beginTransaction();
try {

tx = session.beginTransaction();
Criteria criteria = session.createCriteria(Payment.class);
criteria.add(Expression.sql("to_char(order_date) = '27-OCT-06'"));

List list = criteria.list();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle9i

The generated SQL (show_sql=true):
select this_.PAYMENT_REQUEST_EID as PAYMENT1_0_, this_.ORDER_ID as ORDER2_0_0_, this_.ORDER_DATE as ORDER3_0_0_ from PAYMENT_REQUEST this_ where to_char(order_date) = '27-OCT-06'

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

This query returns no results but I am sure it should return two rows because I run the generate SQL.

Please help!
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 7:30 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Most probably the to_char function convert your date to other format. Or maybe you must specify the format that you desire:
Code:
to_char(my_date, 'DD-MM-YYYY') = '30-12-2006'

Kind Regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 11:46 am 
Newbie

Joined: Sat Nov 04, 2006 3:43 pm
Posts: 9
Marco,
Thank you so much for your answer. It works! But, I prefer not to use the to_char function because I don't want to add any sql function to it.

I would like to be able to do with the following code:

Calendar cal = Calendar.getInstance();
Criteria criteria = session.createCriteria(Payment.class);
criteria.add(Expression.eq("orderDate", new Date(cal.getTimeInMillis()));

where
orderDate is a property of the pojo Payment class.

It does not work for me, do you know what I did wrong?

Thanks!
Rob


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.