-->
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: Order by subattribute in HQL results in wrong SQL query
PostPosted: Mon Nov 13, 2006 6:46 pm 
Beginner
Beginner

Joined: Mon Mar 20, 2006 7:59 am
Posts: 30
Hello,

I am using Beta2 of NHibernate and another issue occured to me (maybe I had this error before as well...)

I have two classes: class Task and class TaskCategory. Now I want to do a (hql)query like that:
Code:
SELECT t.Id FROM Task t order by t.Category.Name


NHibernate translates this query into this sql query:
Code:
select task0_.Id as x0_0_ from Tasks task0_, TaskCategories taskcatego1_ where task0_.CategoryId=taskcatego1_.Id order by  taskcatego1_.Name


As you can see NHibernate does not use outer joins - therefore all the tasks that have no associated category don't get fetched.

I would have expected this query:
Code:
select task0_.Id as x0_0_ from Tasks task0_ LEFT OUTER JOIN TaskCategories taskcatego1_ ON task0_.CategoryId=taskcatego1_.Id order by  taskcatego1_.Name


Is it possible to make NHibernate query like I want? :)

Btw: my mapping of class Task looks something like this:
Code:
   <class name="Task" table="Tasks" >
      <id name="Id" column="Id" unsaved-value="0">
         <generator class="native" />
      </id>

      <many-to-one name="Category" column="CategoryId"  outer-join="true"
                foreign-key="FK_Tasks_Category" class="TaskCategory" />
   </class>


I hope you'll help me. Thank you in advance,
Dominik


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.