Skip to content

Commit 0f32f3e

Browse files
David EllingsworthDavid Ellingsworth
David Ellingsworth
authored and
David Ellingsworth
committed
GH2201: Add option to disable loop detection during query fetches.
1 parent 2f842b5 commit 0f32f3e

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/NHibernate/Cfg/Environment.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ public static string Version
110110
public const string CurrentSessionContextClass = "current_session_context_class";
111111
public const string UseSqlComments = "use_sql_comments";
112112

113+
/// <summary>
114+
/// Enable or disable the ability to detect loops in query fetches.
115+
/// The default is to detect and elimate potential fetch loops.
116+
/// </summary>
117+
public const string DetectFetchLoops = "detect_fetch_loops";
118+
113119
/// <summary> Enable formatting of SQL logged to the console</summary>
114120
public const string FormatSql = "format_sql";
115121

src/NHibernate/Cfg/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public Settings()
3636
public SqlStatementLogger SqlStatementLogger { get; internal set; }
3737

3838
public int MaximumFetchDepth { get; internal set; }
39+
public bool DetectFetchLoops { get; internal set; }
3940

4041
public IDictionary<string, string> QuerySubstitutions { get; internal set; }
4142

src/NHibernate/Cfg/SettingsFactory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public Settings BuildSettings(IDictionary<string, string> properties)
9292
log.Info("Maximum outer join fetch depth: {0}", maxFetchDepth);
9393
}
9494

95+
bool detectFetchLoops = PropertiesHelper.GetBoolean(Environment.DetectFetchLoops, properties, true);
96+
log.Info("Detect fetch loops: {0}", EnabledDisabled(detectFetchLoops));
97+
settings.DetectFetchLoops = detectFetchLoops;
98+
9599
IConnectionProvider connectionProvider = ConnectionProviderFactory.NewConnectionProvider(properties);
96100
ITransactionFactory transactionFactory = CreateTransactionFactory(properties);
97101
// TransactionManagerLookup transactionManagerLookup = TransactionManagerLookupFactory.GetTransactionManagerLookup( properties );

src/NHibernate/Loader/JoinWalker.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,15 @@ protected virtual string GenerateRootAlias(string description)
804804
/// </summary>
805805
protected virtual bool IsDuplicateAssociation(string foreignKeyTable, string[] foreignKeyColumns)
806806
{
807-
AssociationKey associationKey = new AssociationKey(foreignKeyColumns, foreignKeyTable);
808-
return !visitedAssociationKeys.Add(associationKey);
807+
bool detectFetchLoops = Factory.Settings.DetectFetchLoops;
808+
809+
if (detectFetchLoops)
810+
{
811+
AssociationKey associationKey = new AssociationKey(foreignKeyColumns, foreignKeyTable);
812+
return !visitedAssociationKeys.Add(associationKey);
813+
}
814+
815+
return false;
809816
}
810817

811818
/// <summary>

0 commit comments

Comments
 (0)