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?