-->
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.  [ 2 posts ] 
Author Message
 Post subject: ICriteria JoinType determination
PostPosted: Mon May 01, 2006 3:40 am 
Beginner
Beginner

Joined: Fri Jul 29, 2005 10:34 am
Posts: 25
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.0.2

Mapping documents : Just take any Many:1

The generated SQL (show_sql=true): Generates inner joins instead of expected Outer Join

When using ICriteria , i thought it was going to use the XML definition to determine what join type it should use for creating the query. I was wrong since this did not happened.

Second, i thought that by using SetFetchMode() on the just created criteria would be the solution to my problem (my problem was that all manually created criterias where generated using INNER JOIN instead of OUTER JOIN).

Example Code:
_criteria.CreateAlias("HERKOMST", "HERKOMST").SetFetchMode("HERKOMST", NHibernate.FetchMode.Join);

In the source code it's documented that many:1 are not supported but i think this is a limitation that should not be there.. (look at ICriteria.cs SetFetchMode comments)

I've debuged the Nhibernate code and came to this fix:


CriteriaLoader.cs



Code:
protected override JoinType GetJoinType(
         IAssociationType type,
         OuterJoinFetchStrategy config,
         string path,
         string table,
         string[] foreignKeyColumns,
         ISessionFactoryImplementor factory )
      {
         if ( criteria.IsJoin( path ) )
         {
            return JoinType.InnerJoin;
      
      
      protected override JoinType GetJoinType(
         IAssociationType type,
         OuterJoinFetchStrategy config,
         string path,
         string table,
         string[] foreignKeyColumns,
         ISessionFactoryImplementor factory )
      {
         if ( criteria.IsJoin( path ) )
         {
                // STA 28-4-2006 : Modified
                FetchMode fm = criteria.GetFetchMode( path );
                if (fm == FetchMode.Join || fm == FetchMode.Eager)
                    return JoinType.LeftOuterJoin;
                else
                    return JoinType.InnerJoin;

            //return JoinType.InnerJoin;
         }


Any comments?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 5:23 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This part of code was refactored since 1.0.2 so I'll need to check whether it still fails in the current SVN version.


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