Skip to content

Commit 8bc24b7

Browse files
Use a statically resolved dialect when building the session factory
This by the way allows NHibernate.Spatial dialect hack to work again, see nhibernate/NHibernate.Spatial#104
1 parent 95dda1d commit 8bc24b7

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/NHibernate/Cfg/Configuration.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,7 @@ protected virtual void ConfigureProxyFactoryFactory()
12881288

12891289
#endregion
12901290
}
1291+
12911292
/// <summary>
12921293
/// Instantiate a new <see cref="ISessionFactory" />, using the properties and mappings in this
12931294
/// configuration. The <see cref="ISessionFactory" /> will be immutable, so changes made to the
@@ -1296,17 +1297,33 @@ protected virtual void ConfigureProxyFactoryFactory()
12961297
/// <returns>An <see cref="ISessionFactory" /> instance.</returns>
12971298
public ISessionFactory BuildSessionFactory()
12981299
{
1300+
var dynamicDialectMapping = mapping;
1301+
// Use a mapping which does store the dialect instead of instantiating a new one
1302+
// at each access. The dialect does not change while building a session factory.
1303+
// It furthermore allows some hack on NHibernate.Spatial side to go on working,
1304+
// See nhibernate/NHibernate.Spatial#104
1305+
mapping = new StaticDialectMappingWrapper(mapping);
1306+
try
1307+
{
1308+
ConfigureProxyFactoryFactory();
1309+
SecondPassCompile();
1310+
Validate();
1311+
Environment.VerifyProperties(properties);
1312+
Settings settings = BuildSettings();
12991313

1300-
ConfigureProxyFactoryFactory();
1301-
SecondPassCompile();
1302-
Validate();
1303-
Environment.VerifyProperties(properties);
1304-
Settings settings = BuildSettings();
1305-
1306-
// Ok, don't need schemas anymore, so free them
1307-
Schemas = null;
1314+
// Ok, don't need schemas anymore, so free them
1315+
Schemas = null;
13081316

1309-
return new SessionFactoryImpl(this, new StaticDialectMappingWrapper(mapping), settings, GetInitializedEventListeners());
1317+
return new SessionFactoryImpl(
1318+
this,
1319+
mapping,
1320+
settings,
1321+
GetInitializedEventListeners());
1322+
}
1323+
finally
1324+
{
1325+
mapping = dynamicDialectMapping;
1326+
}
13101327
}
13111328

13121329
/// <summary>

0 commit comments

Comments
 (0)