I found out why the result set in second case is empty: for some reason hibernate generates inner joins where left outer joins are expected, e.g.:
Code:
select this_.article_id as article1_0_5_, this_1_.archived as archived0_5_, this_1_.author_id as author5_0_5_, this_1_.content_id as content6_0_5_, this_1_.last_modified as last3_0_5_, this_1_.schema_name as schema4_0_5_, this_.approval_time_limit as approval2_2_5_, this_.author_approval as author3_2_5_, this_.base_article_id as base13_2_5_, this_.category_id as category10_2_5_, this_.comment_policy as comment4_2_5_, this_.editor_id as editor12_2_5_, this_.expiration_date as expiration5_2_5_, this_.magazine_id as magazine11_2_5_, this_.publication_date as publicat6_2_5_, this_.published as published2_5_, this_.superseded_article_id as superseded14_2_5_, this_.temporarily_offline_date as temporar8_2_5_, this_.temporarilyOffline as temporar9_2_5_, author2_.person_id as person1_10_0_, author2_.active as active10_0_, author2_.mail_address as mail3_10_0_, author2_.name as name10_0_, content1_.content_id as content1_13_1_, content1_.xml_data as xml2_13_1_, content1_.external_author as external3_13_1_, content1_.teaser as teaser13_1_, content1_.teaser_image_id as teaser5_13_1_, content1_.title as title13_1_, basearticl3_.article_id as article1_0_2_, basearticl3_1_.archived as archived0_2_, basearticl3_1_.author_id as author5_0_2_, basearticl3_1_.content_id as content6_0_2_, basearticl3_1_.last_modified as last3_0_2_, basearticl3_1_.schema_name as schema4_0_2_, basearticl3_.publicly_visible as publicly2_1_2_, basearticl3_.submission_date as submission3_1_2_, baauthor4_.person_id as person1_10_3_, baauthor4_.active as active10_3_, baauthor4_.mail_address as mail3_10_3_, baauthor4_.name as name10_3_, articlecon10_.content_id as content1_13_4_, articlecon10_.xml_data as xml2_13_4_, articlecon10_.external_author as external3_13_4_, articlecon10_.teaser as teaser13_4_, articlecon10_.teaser_image_id as teaser5_13_4_, articlecon10_.title as title13_4_ from edited_article this_
inner join article this_1_ on this_.article_id=this_1_.article_id
inner join person author2_ on this_1_.author_id=author2_.person_id
inner join content content1_ on this_1_.content_id=content1_.content_id
--inner join base_article basearticl3_ on this_.base_article_id=basearticl3_.article_id
left outer join base_article basearticl3_ on this_.base_article_id=basearticl3_.article_id
left outer join article basearticl3_1_ on basearticl3_.article_id=basearticl3_1_.article_id
--inner join person baauthor4_ on basearticl3_1_.author_id=baauthor4_.person_id
left outer join person baauthor4_ on basearticl3_1_.author_id=baauthor4_.person_id
left outer join content articlecon10_ on basearticl3_1_.content_id=articlecon10_.content_id
where this_.magazine_id=1 and this_.editor_id is null and this_.author_approval='accepted' and this_1_.archived='f' and this_.published='t' and this_.temporarilyOffline='f' order by content1_.external_author desc, author2_.name desc, baauthor4_.name asc limit 25;
I have replaced the two commented out lines (beginning with "-- inner join..") with "left outer join" and got the expected results.
The question is, why does hibernate generate inner joins here? The association to baseArticle is marked as nullable:
Code:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="base_article_id", nullable=true)
private BaseArticle baseArticle;
Shouldn't this force hibernate to create left outer joins?
cheers,
jenner