@@ -239,6 +239,40 @@ public bool HasNonIdentifierPropertyNamedId(string className)
239
239
NHibernate . Dialect . Dialect . GetDialect ( configuration . Properties ) ;
240
240
}
241
241
242
+ [ Serializable ]
243
+ private class StaticDialectMappingWrapper : IMapping
244
+ {
245
+ private readonly IMapping _mapping ;
246
+
247
+ public StaticDialectMappingWrapper ( IMapping mapping )
248
+ {
249
+ _mapping = mapping ;
250
+ Dialect = mapping . Dialect ;
251
+ }
252
+
253
+ public IType GetIdentifierType ( string className )
254
+ {
255
+ return _mapping . GetIdentifierType ( className ) ;
256
+ }
257
+
258
+ public string GetIdentifierPropertyName ( string className )
259
+ {
260
+ return _mapping . GetIdentifierPropertyName ( className ) ;
261
+ }
262
+
263
+ public IType GetReferencedPropertyType ( string className , string propertyName )
264
+ {
265
+ return _mapping . GetReferencedPropertyType ( className , propertyName ) ;
266
+ }
267
+
268
+ public bool HasNonIdentifierPropertyNamedId ( string className )
269
+ {
270
+ return _mapping . HasNonIdentifierPropertyNamedId ( className ) ;
271
+ }
272
+
273
+ public Dialect . Dialect Dialect { get ; }
274
+ }
275
+
242
276
private IMapping mapping ;
243
277
244
278
protected Configuration ( SettingsFactory settingsFactory )
@@ -1254,6 +1288,7 @@ protected virtual void ConfigureProxyFactoryFactory()
1254
1288
1255
1289
#endregion
1256
1290
}
1291
+
1257
1292
/// <summary>
1258
1293
/// Instantiate a new <see cref="ISessionFactory" />, using the properties and mappings in this
1259
1294
/// configuration. The <see cref="ISessionFactory" /> will be immutable, so changes made to the
@@ -1262,17 +1297,33 @@ protected virtual void ConfigureProxyFactoryFactory()
1262
1297
/// <returns>An <see cref="ISessionFactory" /> instance.</returns>
1263
1298
public ISessionFactory BuildSessionFactory ( )
1264
1299
{
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 ( ) ;
1265
1313
1266
- ConfigureProxyFactoryFactory ( ) ;
1267
- SecondPassCompile ( ) ;
1268
- Validate ( ) ;
1269
- Environment . VerifyProperties ( properties ) ;
1270
- Settings settings = BuildSettings ( ) ;
1271
-
1272
- // Ok, don't need schemas anymore, so free them
1273
- Schemas = null ;
1314
+ // Ok, don't need schemas anymore, so free them
1315
+ Schemas = null ;
1274
1316
1275
- return new SessionFactoryImpl ( this , mapping , settings , GetInitializedEventListeners ( ) ) ;
1317
+ return new SessionFactoryImpl (
1318
+ this ,
1319
+ mapping ,
1320
+ settings ,
1321
+ GetInitializedEventListeners ( ) ) ;
1322
+ }
1323
+ finally
1324
+ {
1325
+ mapping = dynamicDialectMapping ;
1326
+ }
1276
1327
}
1277
1328
1278
1329
/// <summary>
0 commit comments