• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

help on HQL

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm peforming the following HQL but get 0 results, but according to database I should get 1 result. Now if I execute the SQL generated by this HQL query I get a result, which is correct.

Any ideas why HQL is not working properly?
==========================================================
Participant p = (Participant)getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Criteria c = session.createCriteria(Participant.class);
c.add(Restrictions.eq(propertyName, value));
List l = c.list();
if (l == null || l.size() == 0) {
return null;
}
if (l.size() > 1) { // this should never happen...
throw new HibernateException("More than one Participant found with " + propertyName + " = " + value);
}
return (Participant)l.get(0);
}
}
);

=====================================================

Thanks!!!
[ September 10, 2007: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, it is a Hibernate Criteria query, rather than HQL.
Second, I think it will help to start with a simpler version of this code (without callbacks, with constant property name/value) and see at which level of complexity it stops working as expected.
 
Marco Moreno
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not get any results when I take HibernateCallback out. But I get results when I take out restrictions and have something like this:
Criteria c = getSession().createCriteria(Participant.class);
//c.add(Restrictions.eq(propertyName, value));
List l = c.list();

But when I add the restriction I get no results. Now I took the SQL generated by this, execute it and it did returned result. So I guess the Restrictions is not working properly?
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To have a chance of understanding what is going on here, one needs to get
specific: what property and value you specify, what SQL you get generated
and execute, how the Participant class is defined and mapped, what is in the database,... I think one can start with this list
reply
    Bookmark Topic Watch Topic
  • New Topic