Skip to content

Commit f27a036

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

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void HandleEntityNotFound(string entityName, string propertyName, object
110110
[NonSerialized]
111111
private readonly IDictionary<string, ICollectionMetadata> collectionMetadata;
112112
[NonSerialized]
113-
private readonly Dictionary<string, ICollectionPersister> collectionPersisters;
113+
private readonly IDictionary<string, ICollectionPersister> collectionPersisters;
114114
[NonSerialized]
115115
private readonly ILookup<string, ICollectionPersister> collectionPersistersSpaces;
116116

@@ -296,7 +296,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
296296
classMetadata = new ReadOnlyDictionary<string, IClassMetadata>(classMeta);
297297

298298
Dictionary<string, ISet<string>> tmpEntityToCollectionRoleMap = new Dictionary<string, ISet<string>>();
299-
collectionPersisters = new Dictionary<string, ICollectionPersister>();
299+
var collPersisters = new Dictionary<string, ICollectionPersister>();
300300
foreach (Mapping.Collection model in cfg.CollectionMappings)
301301
{
302302
var cache = GetCacheConcurrencyStrategy(
@@ -306,7 +306,7 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
306306
model.OwnerEntityName,
307307
caches);
308308
var persister = PersisterFactory.CreateCollectionPersister(model, cache, this);
309-
collectionPersisters[model.Role] = persister;
309+
collPersisters[model.Role] = persister;
310310
IType indexType = persister.IndexType;
311311
if (indexType != null && indexType.IsAssociationType && !indexType.IsAnyType)
312312
{
@@ -333,6 +333,8 @@ public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings
333333
}
334334
}
335335

336+
collectionPersisters = new ReadOnlyDictionary<string, ICollectionPersister>(collPersisters);
337+
336338
collectionPersistersSpaces = collectionPersisters
337339
.SelectMany(x => x.Value.CollectionSpaces.Select(y => new { QuerySpace = y, Persister = x.Value }))
338340
.ToLookup(x => x.QuerySpace, x => x.Persister);

0 commit comments

Comments
 (0)