-->
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.  [ 7 posts ] 
Author Message
 Post subject: HQL doesn't return data but sql query does it
PostPosted: Mon Sep 27, 2004 8:28 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
Hi alls

Hibernate version: 2.1.6 and the latest from CVS

Name and version of the database you are using: Postgres 7.3.4 under Windows XP

I've got such hql query

Code:
select prop.value, report.status.code, count(*) from Report as report, CompanyProperty as prop
where report.deleted = 'FALSE' and report.organization.id in
(:myOrgKeys) and prop.refId = report.organization.id and prop.language.id=1 and prop.name = 'name' group by prop.value,
* report.status.code, prop.value order by LOWER(prop.value)


When i execute this query :

Code:
final Query q = session.getSession().getNamedQuery(Report.GET_STATISTIC_FOR_ORGANIZATION_SET);

/**
*  orgIds is ArrayList with one java.lang.Long = 47
*/

q.setParameter("myOrgKeys", orgIds);
data = q.list();


Hibernate generate such sql code:
Code:
select companypro1_.value as x0_0_, reportstat2_.code as x1_0_, count(*) as x2_0_ from report report0_,
multilanguage_property companypro1_, report_status reportstat2_ where companypro1_.disc='comp' and
report0_.status_id=reportstat2_.status_id and ((report0_.deleted='FALSE' )and(report0_.org_id in(?))and
(companypro1_.ref_id=report0_.org_id )and(companypro1_.lang_id=1 )and(companypro1_.name='name' ))
group by  companypro1_.value , reportstat2_.code , companypro1_.value order by  LOWER(companypro1_.value)


And i've got empty list but if i execute sql query i've got 2 rows
Result : "2 rows fetched (0,19 sec)"

So i think there's a bug in hibernate that it doesn't return data which present in database or am i wrong ?

thank's[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 8:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Negative. Look elswhere for your bug.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 8:37 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
Negative. Look elswhere for your bug.

Could you explain who it can be my bug if hql query returns nothing
but sql query generated by hibernate returns right data ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 8:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Sure. The explanation is that you made a mistake somewhere :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 9:26 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
Sure. The explanation is that you made a mistake somewhere :)

:) nice answer
but here's hql query

Code:
select prop.value, report.status.code, count(*) from Report as report, CompanyProperty as prop where report.deleted = 'FALSE' and report.organization.id in (:myOrgKeys) and prop.refId = report.organization.id and prop.language.id=1 and prop.name = 'name' group by prop.value, report.status.code, prop.value order by LOWER(prop.value)

i execute it and no data.
then i execute in sql query which was generated by hibernate and there're 2 rows return.

Now i rewrote hql and set list of id static

it was
Code:
...report.organization.id in (:myOrgKeys) ...

now it's
Code:
...report.organization.id in (47, 1532) ...

and such query returns data

I rechecked that ArrayList
Code:
query.setParameter("myOrgKeys", orgIds);

contains 2 Long with 47 and 1532 value.

So i can't see where my bug can hide :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 9:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
looks to me like you meant to use setParameterList()


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 27, 2004 9:37 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
looks to me like you meant to use setParameterList()

Yes, You're right ! Feelling myself like a last fool :(
Thank's


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