-->
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.  [ 9 posts ] 
Author Message
 Post subject: HQL parameters in subqueries
PostPosted: Mon Apr 19, 2004 5:18 am 
Newbie

Joined: Thu Feb 26, 2004 10:19 am
Posts: 8
Location: Passau, Germany
Hi !

Isn't it possible, to have parameters in subqueries ?
Here's may query and the excepetion thrown by hibernate:

queryString =
"select qst.id "
+ "from questions.DBAssessQuestion as qst "
+ "where qst.metaData.values in elements ( "
+ " from metadata.IntegerDimValue as dimVal "
+ " where dimVal.dimension = :dimension "
+ " and dimVal.intValue = :intValue "
+ ")";

Query query = session.createQuery(queryString);
query.setEntity("dimension", intVal.getDimension());
query.setEntity("intValue", intVal.getIntValue());

The subquery (from metadate ... :intValue) runs without problem if used standalone. But this question throws the following exception:

net.sf.hibernate.QueryException: Named parameter does not appear in Query: dimension [select qst.id from questions.DBAssessQuestion as qst where qst.metaData.values in elements ( from metadata.IntegerDimValue as dimVal where dimVal.dimension = :lDim and dimVal.intValue = :intValue )]

...or is it just a odd error-message and the problem is somewhere else in the question?

Thanks for any hint !

P.S.: I'm using hibernate 2.1.2


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 6:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
values is a collection? Then it should be something like:
Code:
select qst.id from questions.DBAssessQuestion as qst
  join qst.metaData.values value
  where value in elements ...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 7:02 am 
Newbie

Joined: Thu Feb 26, 2004 10:19 am
Posts: 8
Location: Passau, Germany
Thank you for your quick response:

Yes ! values is a collection (more precisely: a java.util.List).

I changed now the query as you suggested it:

Code:
queryString = "select qst.id "
         + "from questions.DBAssessQuestion as qst "
         + "join qst.metaData.values as value "
         + "where value in elements ( "
         + "   from metadata.IntegerDimValue as dimVal "
         + "   where dimVal.dimension = :dimension "
         + "   and dimVal.intValue = :intValue  "
          ")";



Unfortunatly, the exception remains the same:
Code:
net.sf.hibernate.QueryException: Named parameter does not appear in Query: dimension


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 9:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Check your code. The exception message tells you quite clearly that the parameter is really named :lDim.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 9:56 am 
Newbie

Joined: Thu Feb 26, 2004 10:19 am
Posts: 8
Location: Passau, Germany
Hi !

...and sorry for the confusion:
The error-message in my first positing had a copy&paste error. (I tried several parameter-names since there were some postings in this forum, saying that the hql-parser in older hibernate version had problems with some parameter-names.)

In fact: Hibernate really complains about the paramter "dimension" (and not "lDim")

So here is the original exception-text:

Code:
net.sf.hibernate.QueryException: Named parameter does not appear in Query: dimension [select qst.id from questions.DBAssessQuestion as qst join qst.metaData.values value where value in elements (  from metadata.IntegerDimValue as dimVal  where dimVal.dimension = :dimension  and dimVal.intValue = :intValue  )]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 10:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Submit a simple test case to JIRA. May be a bug with the new named-parameter-validation stuff.

Max, is that a possibility?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 3:56 am 
Newbie

Joined: Thu Feb 26, 2004 10:19 am
Posts: 8
Location: Passau, Germany
...one week later. :-(

I finally got the time to set up a simple test case. I submitted it now to JIRA as you suggested. The report-number is HB-915.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 5:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The correct, working query is:

Code:
select qst.id
from DBAssessQuestion as qst
   join qst.metaData.values value
where value in ( 
   from IntegerDimValue as dimVal
   where dimVal.dimension = :dimension  and dimVal.intValue = :intValue 
)



The elements() construct applies to collections, not subqueries.

Sorry about the confusing exception message.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 5:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
An alternative, equivalent formulation of this query is:

Code:
select qst.id
from DBAssessQuestion as qst
   join qst.metaData.values value,
   IntegerDimValue as dimVal
where dimVal.dimension = :dimension 
   and dimVal.intValue = :intValue
   and dimVal = value



And a much, much better formulation is:

Code:
select qst.id
from DBAssessQuestion as qst
   join qst.metaData.values value
where value.dimension = :dimension 
   and value.intValue = :intValue


I don't know why you had this unnecessary subselect.


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