-->
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.  [ 5 posts ] 
Author Message
 Post subject: Bad sql generated with DetachedQuery
PostPosted: Mon Aug 14, 2006 4:06 pm 
Newbie

Joined: Sat Mar 11, 2006 4:15 pm
Posts: 15
Hibernate version:
hibernate 3.2.0 cr2
hiberate-annotations 3.2.0 cr1

I have the following criteria:

DetachedCriteria crit = DetachedCriteria.forClass(getEntityClass())
.createAlias("categories", "cat")
.createAlias("cat.allParents", "category")
.createAlias("category.allChildren", "child")
.createAlias("child.cards", "card")
.add(eqProperty("id", "card.id"))
.add(eq("category.id", cat.getId() ))
.setProjection(distinct(property("id")));

return createCriteria(getSession())
.add(Subqueries.propertyIn("id", crit));

When I run the first block as it's own query it executes fine. But used as a detached query (as a subquery) i get the following:

SEVERE: Column not found: CARD4_.ID in statement [
select top ? this_.id (... more columns ...)
from Card this_
where this_.id in (
select distinct this0__.id as y0_
from Card this0__
where this0__.id=card4_.id and category2_.id=?)
order by this_.id asc
]

It appears that it never generated the sql for the joins and such in the subquery. Is this a bug or am I doing something wrong? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 5:07 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Will something like this work?

Code:
return createCriteria( getSession() )
          .add( Property.forName("id").in( crit ) );


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 5:36 pm 
Newbie

Joined: Sat Mar 11, 2006 4:15 pm
Posts: 15
bkmr_77 wrote:
Will something like this work?

Code:
return createCriteria( getSession() )
          .add( Property.forName("id").in( crit ) );


nope, i was actually trying that before. the problem is that it doesn't generate sql for joins in subqueries. it appears to be a bug that's been open since 2003. :(

http://opensource.atlassian.com/project ... se/HHH-158


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 4:28 pm 
Newbie

Joined: Thu Dec 01, 2005 11:34 am
Posts: 19
hagios17 wrote:
bkmr_77 wrote:
Will something like this work?

Code:
return createCriteria( getSession() )
          .add( Property.forName("id").in( crit ) );


nope, i was actually trying that before. the problem is that it doesn't generate sql for joins in subqueries. it appears to be a bug that's been open since 2003. :(

http://opensource.atlassian.com/project ... se/HHH-158


Did the patch that was listed off of your link fix the problem for you?

I'm struggling massively with this problem, and I'd like to know if anyone has gotten it working yet. As far as I can tell, the patch that was listed did not fix my issue (which is the exact same as yours!)

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 27, 2006 4:37 pm 
Newbie

Joined: Thu Dec 01, 2005 11:34 am
Posts: 19
james_nemesh wrote:
hagios17 wrote:
bkmr_77 wrote:


Did the patch that was listed off of your link fix the problem for you?


In reply to myself, yes, the patch works. This kind of query evaluates with Hibernate 3.2CR4:

DetachedCriteria query1 = DetachedCriteria.forClass(PhenoAttributeHistory.class, "pah")
.createAlias("phenoAttributes", "pa")
.createAlias("pa.phenoProjAttributeType", "ppat")
.createAlias("ppat.phenoAttributeType", "pat")
.add(Restrictions.and(Restrictions.eq("pat.name", "BMI"), Restrictions.gt ("pa.valueDouble", 20D)))
.setProjection(Property.forName("lsid"));

DetachedCriteria query2 = DetachedCriteria.forClass(PhenoAttributeHistory.class, "pah")
.createAlias("phenoAttributes", "pa")
.createAlias("pa.phenoProjAttributeType", "ppat")
.createAlias("ppat.phenoAttributeType", "pat")
.add(Restrictions.and(Restrictions.eq("pat.name", "Chol"), Restrictions.gt ("pa.valueDouble", 200D)))
.setProjection(Property.forName("lsid"));

DetachedCriteria query3 = DetachedCriteria.forClass(PhenoAttributeHistory.class, "pah")
.createAlias("phenoAttributes", "pa")
.createAlias("pa.phenoProjAttributeType", "ppat")
.createAlias("ppat.phenoAttributeType", "pat")
.add(Restrictions.and(Restrictions.eq("pat.name", "Weight"), Restrictions.gt ("pa.valueDouble", 160D)))
.setProjection(Property.forName("lsid"));

Criteria andQuery = hsession.createCriteria(PhenoAttributeHistory.class, "pah2")
.add(
Restrictions.and(
Restrictions.and(
(Subqueries.propertyIn("lsid", query1)),
(Subqueries.propertyIn("lsid", query2))),
Subqueries.propertyIn("lsid", query3)));

(sorry about the formatting)


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