-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL works but Criteria doesn't.
PostPosted: Mon Mar 03, 2008 9:10 am 
Newbie

Joined: Wed Dec 27, 2006 3:05 am
Posts: 7
Location: Bangalore
I am using Oracle10g Enterprise edition and Hibernate 3.1.2

This code works fine
Code:
Query query = session.createQuery("from GuardianDetails gd where gd.pan='222'");
List list = query.list();


but when I use Criteria I don't get any result.(nor any error).

Code:
Criteria criteria = session.createCriteria(GuardianDetails.class);
criteria.add(Expression.eq("pan", "222"));
List list = criteria.list();


I don't understand what is going on - even the sql generated by Criteria gives me a result in the db client.

Please help. Any clues ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 10:27 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Instead of Expression.eq, try Restrictions.eq. It should work

Code:
Criteria criteria = session.createCriteria(GuardianDetails.class);
criteria.add(Restrictions.eq("pan", "222"));
List list = criteria.list();


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 04, 2008 12:00 am 
Newbie

Joined: Wed Dec 27, 2006 3:05 am
Posts: 7
Location: Bangalore
Thanks for the input. I have tried both Expression and Restrictions - it's not working. Gives the same sql and no result.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 3:45 am 
Newbie

Joined: Wed Dec 27, 2006 3:05 am
Posts: 7
Location: Bangalore
The solution was interesting and something new to me, so I thought of sharing it here.

Actually the db column 'PAN' is not a VARCHAR2 its a CHAR of length 4. So in order to get a result with that column as the input parameter we have to pass a String of length 4. (PAN is mapped with a String type in hbm.xml) Any data of length less than that will not give you a result, nor any error :-)


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