-->
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.  [ 1 post ] 
Author Message
 Post subject: Equality Comparison on a date attribute using Criteria
PostPosted: Tue Sep 14, 2010 2:48 pm 
Newbie

Joined: Wed Sep 01, 2010 1:18 pm
Posts: 3
Hello all,

I am very new to hibernate. I have a one-to-one relationship between two tables MASTER and ROSTER.
I have correctly mapped a unidirectional one-to-one association from my persistent class Roster to Master.
I need to search all Roster records by transaction_date property of Master.

I have spent hours trying to search for an elegant way to do this query using Criteria, but to no avail. I ended up doing something
like this which gives me the desired output. I actually need to do an equality comparison on date attributes in my table. I am using Oracle as backend.

Code:
Criteria criteria = session.createCriteria(Roster.class);
   criteria.createCriteria("master")
   .add(Restrictions.sqlRestriction("to_char(transaction_date,'MM/DD/YYYY') = '"+transaction_date+"'"));


Can you please let me know a better way to express such query in Hibernate(esp. the one using date comparisons on equality). Your suggestions would be highly appreciated.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.