-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate: Criteria Query with Subselect
PostPosted: Mon Oct 20, 2008 3:45 pm 
Newbie

Joined: Fri Oct 10, 2008 11:58 am
Posts: 1
Hello,

I have a working HQL query that I'm trying to convert to a QBC. The HQL is below. I've taken several stabs at the QBC, and I've included my attempts, too. Any help getting this working (along with an explanation) would be superb!

I think the biggest issue I'm having trouble with the really just a naming issue. In the HQL, I can say "from Task t" and then refer to "t" on its own. In QBC, I can refer to fields in the Task item, but not the Task item itself (at least I can't find this).

Thanks!
Lavie

This returns a list of Task objects.

Code:
from Task t                                 
where t.loc.locSeq = :Location               
  and t.status < 6                           
  and t.type in (                           
                :Categories                 
                )                           
  and t in (                         
            select ta.task                                       
              from TaskAllocation ta                             
             where ta.participant.participantSeq =   :participantId
           )   



I had a "createAlias("Task" , "t") thinking that I would be able to refer to "t" as a Task. So that's where all the references to "t" come from.
Code:
DetachedCriteria sub1 = DetachedCriteria.forClass(Task.class)
                                   .createAlias("TaskAllocation", "ta")
                                   .setProjection(Property.forName("ta.task"))
                                   .add(Restrictions.eq("ta.participant.participantSeq", new Long(239321)) );
      
List list = session.createCriteria(Task.class)
                              .add(Restrictions.eq("t.loc.locSeq" , new Long(14836)))
                              .add(Restrictions.gt("t.status" , new Integer(6)) )
                              .add(Restrictions.in("t.type", new String[] {"Report"} ) )
                              .add(Property.forName("t").in(sub1)).list();


For this attempt above, which I think is the closest I came, I got the error:
Code:
org.hibernate.QueryException: could not resolve property: Task of: com.mckesson.hac.worklist.om.Task
   at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)
   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
   at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1379)
   at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
   at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1354)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:434)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:394)
   at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:45)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
   at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:90)
   at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:59)
   at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
   at staff.StaffIdManager.getTasksByCriteria(StaffIdManager.java:85)
   at staff.StaffIdManager.main(StaffIdManager.java:23)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.