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,