-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL query problem
PostPosted: Thu Feb 24, 2011 8:34 am 
Newbie

Joined: Sat Jun 09, 2007 12:29 pm
Posts: 19
Hi,

I'm having problem with the HQL query. I'm using MySQL.
This is my query:

Code:
select
   o.uuid as uuid,
   o.code as code,
   o.title as title,
   o.category.category as category,
   o.priority.priority as priority,
   o.difficulty.difficulty as difficulty,
   o.type.type as type,
   o.status.status as status,
   o.status.color as recColor,
   o.timeEstimate.description as timeEstimate,
   o.date as date
from Task o
   left join o.category
   left join o.priority
   left join o.difficulty
   left join o.type
   left join o.status
   left join o.timeEstimate


this code produces following SQL:

Code:
select
   task0_.uuid as col_0_0_,
   task0_.code as col_1_0_,
   task0_.title as col_2_0_,
   taskcatego7_.category as col_3_0_,
   taskpriori8_.priority as col_4_0_,
   taskdiffic9_.difficulty as col_5_0_,
   tasktype10_.type as col_6_0_,
   taskstatus11_.status as col_7_0_,
   taskstatus11_.color as col_8_0_,
   tasktimedu13_.description as col_9_0_,
   task0_.date as col_10_0_
from
   Po_Task task0_ inner join Set_PersistentRecord task0_1_ on task0_.uuid=task0_1_.uuid
      left outer join Po_SetTaskCategory taskcatego1_ on task0_.categoryUuid=taskcatego1_.uuid
      left outer join Set_PersistentRecord taskcatego1_1_ on taskcatego1_.uuid=taskcatego1_1_.uuid
      left outer join Po_SetTaskPriority taskpriori2_ on task0_.priorityUuid=taskpriori2_.uuid
      left outer join Set_PersistentRecord taskpriori2_1_ on taskpriori2_.uuid=taskpriori2_1_.uuid
      left outer join Po_SetTaskDifficulty taskdiffic3_ on task0_.difficultyUuid=taskdiffic3_.uuid
      left outer join Set_PersistentRecord taskdiffic3_1_ on taskdiffic3_.uuid=taskdiffic3_1_.uuid
      left outer join Po_SetTaskType tasktype4_ on task0_.typeUuid=tasktype4_.uuid
      left outer join Set_PersistentRecord tasktype4_1_ on tasktype4_.uuid=tasktype4_1_.uuid
      left outer join Po_SetTaskStatus taskstatus5_ on task0_.statusUuid=taskstatus5_.uuid
      left outer join Set_PersistentRecord taskstatus5_1_ on taskstatus5_.uuid=taskstatus5_1_.uuid
      left outer join Po_SetTaskTimeDuration tasktimedu6_ on task0_.timeEstimateUuid=tasktimedu6_.uuid
      left outer join Set_PersistentRecord tasktimedu6_1_ on tasktimedu6_.uuid=tasktimedu6_1_.uuid,
   Po_SetTaskCategory taskcatego7_ inner join Set_PersistentRecord taskcatego7_1_ on taskcatego7_.uuid=taskcatego7_1_.uuid,
   Po_SetTaskPriority taskpriori8_ inner join Set_PersistentRecord taskpriori8_1_ on taskpriori8_.uuid=taskpriori8_1_.uuid,
   Po_SetTaskDifficulty taskdiffic9_ inner join Set_PersistentRecord taskdiffic9_1_ on taskdiffic9_.uuid=taskdiffic9_1_.uuid,
   Po_SetTaskType tasktype10_ inner join Set_PersistentRecord tasktype10_1_ on tasktype10_.uuid=tasktype10_1_.uuid,
   Po_SetTaskStatus taskstatus11_ inner join Set_PersistentRecord taskstatus11_1_ on taskstatus11_.uuid=taskstatus11_1_.uuid,
   Po_SetTaskTimeDuration tasktimedu13_ inner join Set_PersistentRecord tasktimedu13_1_ on tasktimedu13_.uuid=tasktimedu13_1_.uuid
where
   task0_.categoryUuid=taskcatego7_.uuid and
   task0_.priorityUuid=taskpriori8_.uuid and
   task0_.difficultyUuid=taskdiffic9_.uuid and
   task0_.typeUuid=tasktype10_.uuid and
   task0_.statusUuid=taskstatus11_.uuid and
   task0_.timeEstimateUuid=tasktimedu13_.uuid


TimeEstimate is not mandatory for the Task and can have null value. Now in my case no record is found as the generated code is task0_.timeEstimateUuid=tasktimedu13_.uuid

How should I change HQL to get proper results?

_________________
http://www.objectverse.com
http://www.alcyone.si
http://blog.alcyone.si


Top
 Profile  
 
 Post subject: Re: HQL query problem
PostPosted: Thu Feb 24, 2011 8:55 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
All variants in the selection list of the form 'o.category.category' (eg. implicit join) generate an inner join as described in the documentation: http://docs.jboss.org/hibernate/core/3. ... oins-forms

If you want to use a left join you need to assign an alias to the joins you have included and use that alias in the selection:

Code:
select
...
   c.category as category,
....
from Task o
  left join o.category c
....


Top
 Profile  
 
 Post subject: Re: HQL query problem
PostPosted: Thu Feb 24, 2011 10:18 am 
Newbie

Joined: Sat Jun 09, 2007 12:29 pm
Posts: 19
That was it. Thank you.

_________________
http://www.objectverse.com
http://www.alcyone.si
http://blog.alcyone.si


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