-->
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.  [ 5 posts ] 
Author Message
 Post subject: Comparing dates with Restrictions.eq
PostPosted: Thu Feb 28, 2008 12:16 pm 
Beginner
Beginner

Joined: Thu Feb 28, 2008 11:53 am
Posts: 23
Hi guys,

I'm using Hibernate 3.1 and Oracle 10g and I'm comparing a Date field in my Hibernate object, typed as Date also in my Hibernate xml mapping file and my Oracle type is Date in my view.

This is how I get the date to compare

Code:
Date d = new SimpleDateFormat("mm/dd/yyyy").parse(obj.getCriteria());


Then I use that Date like this:

Code:
case EQ : return Restrictions.eq(f.getColumn(), ClassToHibernateTypeMapper.mapper(this.clazz, f));


So what this snippet would do is return a Restriction that reads:

Restrictions.eq('dateCreated',d), with d being a Date of format 'mm/dd/yyyy' from above.

My Oracle date is format xx-MON-xx.

I get back absolutely no results when i run the query and I can see the Hibernate query formatted just fine in my Tomcat log. Any suggestions on what I might be doing wrong guys, thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 1:31 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Did you check this

How to compare date with HQL
http://forum.hibernate.org/viewtopic.php?p=2377601&sid=2b5be2f1edd2dd8b5264ed9fd3132a26


Top
 Profile  
 
 Post subject: Nice try but the outcome was the same
PostPosted: Thu Feb 28, 2008 4:22 pm 
Beginner
Beginner

Joined: Thu Feb 28, 2008 11:53 am
Posts: 23
Thanks buddy but it didn't work, this is my code
Code:
   String[] d = obj.getCriteria().split("/");
                cal.set(Integer.parseInt(d[2]),Integer.parseInt(d[0])-1, Integer.parseInt(d[1]));
                o = cal.getTime();


After I split the String date passed in from the user, I then use in set() but I still get back no results.

This is part of the sql snippet generated:

Code:
this_ where this_.date_created=? and 1=1


I never get to see the actual query values passed in though. Any other ideas.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 4:40 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Quote:
I never get to see the actual query values passed in though. Any other ideas.


You have to set the logging for hibernate.type

# Log JDBC bind parameter runtime arguments
log4j.logger.org.hibernate.type=INFO


Top
 Profile  
 
 Post subject: Still nothing
PostPosted: Thu Feb 28, 2008 9:01 pm 
Beginner
Beginner

Joined: Thu Feb 28, 2008 11:53 am
Posts: 23
this is a snippet from my logs

Code:
Hibernate: select this_.request_id as request1_19_0_, this_.date_created as date2_19_0_, this_.division as division19_0_, this_.product_group as product4_19_0_, this_.sale_reporting_code as sale5_19_0_, this_.product_type as product6_19_0_, this_.territory as territory19_0_, this_.presentation as presenta8_19_0_, this_.unitId as unitId19_0_, this_.code as code19_0_, this_.name as name19_0_, this_.unit_typeid as unit12_19_0_, this_.countryTypeId as country13_19_0_, this_.country as country19_0_, this_.collectionId as collect15_19_0_, this_.col_code as col16_19_0_, this_.col_name as col17_19_0_, this_.col_componenttypeid as col18_19_0_, this_.cstateId as cstateId19_0_, this_.cs_code as cs20_19_0_, this_.cs_name as cs21_19_0_, this_.cs_shortcode as cs22_19_0_ from HIBERNATEREQUESTOBJECT2 this_ where lower(this_.cs_name) like ? and 1=1
2008-02-28 19:39:51,948 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to open ResultSet (open ResultSets: 0, globally: 0)>
2008-02-28 19:39:51,948 DEBUG [org.hibernate.loader.Loader] - <result row: EntityKey[net.taxstream.transferpricing.domain.HibernateRequestObject#104]>
2008-02-28 19:39:51,948 DEBUG [org.hibernate.loader.Loader] - <result row: EntityKey[net.taxstream.transferpricing.domain.HibernateRequestObject#121]>


I still can't see the value being passed but the query is executing and a result set is being returned. I've tried Date, Timestamp and Calendar but I stiil can't use Restrictions.eq to compare whether 2 dates are equal. Anybody with any suggestions, does my date format matter? This is all I am missing to make this dynamic sql query work.


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