Skip to content

Commit 96218d1

Browse files
committed
Make SessionFactoryImpl.entityPersisters a ReadOnlyDictionary to line up with how collectionMetadata is built and improve determistic behavior under accidental multithreading
1 parent f27a036 commit 96218d1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
265265
#region Persisters
266266

267267
var caches = new Dictionary<Tuple<string, string>, ICacheConcurrencyStrategy>();
268-
entityPersisters = new Dictionary<string, IEntityPersister>();
268+
var tmpEntityPersisters = new Dictionary<string, IEntityPersister>();
269269
implementorToEntityName = new Dictionary<System.Type, string>();
270270

271271
Dictionary<string, IClassMetadata> classMeta = new Dictionary<string, IClassMetadata>();
@@ -280,7 +280,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
280280
model.EntityName,
281281
caches);
282282
var cp = PersisterFactory.CreateClassPersister(model, cache, this, mapping);
283-
entityPersisters[model.EntityName] = cp;
283+
tmpEntityPersisters[model.EntityName] = cp;
284284
classMeta[model.EntityName] = cp.ClassMetadata;
285285

286286
if (model.HasPocoRepresentation)
@@ -289,14 +289,16 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
289289
}
290290
}
291291

292+
entityPersisters = new ReadOnlyDictionary<string, IEntityPersister>(tmpEntityPersisters);
293+
292294
entityPersistersSpaces = entityPersisters
293295
.SelectMany(x => x.Value.QuerySpaces.Select(y => new { QuerySpace = y, Persister = x.Value }))
294296
.ToLookup(x => x.QuerySpace, x => x.Persister);
295297

296298
classMetadata = new ReadOnlyDictionary<string, IClassMetadata>(classMeta);
297299

298300
Dictionary<string, ISet<string>> tmpEntityToCollectionRoleMap = new Dictionary<string, ISet<string>>();
299-
var collPersisters = new Dictionary<string, ICollectionPersister>();
301+
var tmpCollectionPersisters = new Dictionary<string, ICollectionPersister>();
300302
foreach (Mapping.Collection model in cfg.CollectionMappings)
301303
{
302304
var cache = GetCacheConcurrencyStrategy(
@@ -306,7 +308,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
306308
model.OwnerEntityName,
307309
caches);
308310
var persister = PersisterFactory.CreateCollectionPersister(model, cache, this);
309-
collPersisters[model.Role] = persister;
311+
tmpCollectionPersisters[model.Role] = persister;
310312
IType indexType = persister.IndexType;
311313
if (indexType != null && indexType.IsAssociationType && !indexType.IsAnyType)
312314
{
@@ -333,7 +335,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
333335
}
334336
}
335337

336-
collectionPersisters = new ReadOnlyDictionary<string, ICollectionPersister>(collPersisters);
338+
collectionPersisters = new ReadOnlyDictionary<string, ICollectionPersister>(tmpCollectionPersisters);
337339

338340
collectionPersistersSpaces = collectionPersisters
339341
.SelectMany(x => x.Value.CollectionSpaces.Select(y => new { QuerySpace = y, Persister = x.Value }))

0 commit comments

Comments
 (0)