• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

outer-join not working in hbm.xml file

 
Rajan Nath
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a one-to-one relationship in hbm

<one-to-one name="userProfile" class="UserProfile" lazy="false" outer-join="true" />

as I want even if no matching id is found null should come, but still left join working. I can not set any setting for outer-join in configuration file as it will applicable for all .

Thanks in advance
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
outer-join is not a defined attribute for the one-to-one element. How are you managing to use it?

If what you are after is a null value for your POJO's userProfile property if there is no related userProfile that is just how Hibernate behaves, you don't need to do anything else in your mapping.
 
Rajan Nath
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using criteria and my query is build like
select name from
(Family fp join UserProfile oup on fp.FamilyID = oup.familyid)
which is working.

I want to build like this
select name from
(Family fp left outer join UserProfile oup on fp.FamilyID = oup.familyid)
which I am not to implement
any way to implement, some one suggeted to use "FetchMode.JOIN" but ,I am using
"Criteria.createAlias("userProfile", "userProfileAlias");"
"Criteria.setFetchMode("userProfileAlias",FetchMode.JOIN );"
but still outer join not working
 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dude,

session.createCriteria(FamilyProfile.class, "fp_")
criteria.createAlias("fp_.userProfile", "userProfile_", JoinFragment.LEFT_OUTER_JOIN);

criteria.list();

bam and Done!

Let me know how are ya holding on.
 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Btw, please refrain from naming family profile's id as familyid, all ids should be named as id, it is useful imho when you are writing multiple joins query. Nothing specific though.


Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic