-->
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.  [ 7 posts ] 
Author Message
 Post subject: Strange results with Order By on many-to-one association
PostPosted: Tue Nov 25, 2003 10:20 am 
I am experiencing some problems when using "ORDER BY" clauses (in Hibernate queries)
in combination with (optional) many-to-one associations.


Example:
========

If have a many-to-one between "SellOffer" and "Structure"
This assocation is optional (-> "id_structure" may be null)

Code:
<hibernate-mapping>

    <class name="be.cora.thema2.model.offer.SellOffer" table="fl_sell_offer">

    ...

      <many-to-one name="structure"
          column="id_structure"
         class="be.cora.thema2.model.legacy.Structure"
        cascade="none"
        outer-join="true"/>
       
    </class>   
       
</hibernate-mapping>


I have 18 records in SellOffer, only 6 of them are linked to a structure


CASE ONE
========

When running the HQL:
Code:
"FROM foo IN class be.cora.thema2.model.offer.SellOffer"


I do receive my 18 records (hopefully ;-)


CASE TWO:
=========

I want the same data, but this time sorted by the structure name:
Code:
"FROM foo IN class be.cora.thema2.model.offer.SellOffer ORDER BY foo.structure.structureName"


=> I only receive 6 records !!!
(actually the ones having a non-null structure)

I have examined the SQL statement generated by Hibernate:
Code:
select foo.... , foo.id_structure as id_stru12_
from fl_sell_offer foo, fl_structure structur0_
where foo.id_structure=structur0_.id_structure
order by structur0_.nm_structure desc


And I do not understand why Hibernate is not using an outer-join (+)
(BTW the mapping attribute is named "outer-join") such as:
Code:
where foo.id_structure=structur0_.id_structure(+)

which returns the expected results.


Question:
=========

Is it a bug, or (more probable ;-) do I miss something ?

What should I change (in my mapping, in my query, ....) in order to
get my 18 records sorted by structure name ?

Thx in advance,


Top
  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 10:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
where on earth did you read in the documentation that an implicit join is translated to an outer join?

If you want an outer join, write down an outer join.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 12:12 pm 
Thanks a lot Gavin.
You are right, it is written nowhere :-$

But this leads me to the following suggestion:
I was wondering if, with the help of the not-null attribute in my <many-to-one> mapping, Hibernate could not smartly utilize such information in order to decide how to translate the implicit join:
- if not-null="true" => translated into a normal join
- if not-null="false" => translated into an outer join

What do you think about it ?


Top
  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 12:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
And break existing code?

No way.

I actually think that inner join is a very reasonable and defensible semantic here.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 7:03 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:08 pm
Posts: 26
gavin wrote:
where on earth did you read in the documentation that an implicit join is translated to an outer join?


AFAIK, the documentation (reference manual and HiA) are both silent on this. That is, they don't say how an HQL implicit join gets translated into a SQL join. Since it seems that HQL implicit joins always get translated into SQL inner joins, it would be helpful if the docs actually said "HQL implicit joins always get translated into SQL inner joins".


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 11:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
There is in fact a discussion of this in the docs in CVS (which made it into 3.1rc2 and maybe even 3.1rc1)...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 12:10 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:08 pm
Posts: 26
steve wrote:
There is in fact a discussion of this in the docs in CVS (which made it into 3.1rc2 and maybe even 3.1rc1)...


Cool, yes, I see it there. Thanks!


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