Description
When using the Prevalence cache provider, a NullReferenceException
is thrown from SessionFactoryImpl.GetRealObject
during Configuration.BuildSessionFactory
. This exception occurs because the Prevalence cache provider attempts to unserialize a session factory upon start. The constructor for SessonFactorImpl calls settings.CacheProvider.Start
prior to calling SessionFactoryObjectFactory.AddInstance
. Thus the call to SessionFactoryObjectFactory.GetNamedInstance
in SessionFactoryImpl.GetRealObject
returns null
despite the fact that the SessionFactory that is being deserialized is the one that started the cache provider.
There are a couple of ways to resolve this issue:
- Do not serialize the SessionFactory as part of the cache key. This is the approach taken by Hibernate ORM.
- Add an additional check to
SessionFactoryImpl.GetRealObject
that compares the name of the requested session factory against that of the current session factory prior to callingSessionFactoryObjectFactory.GetNamedInstance
.
Personally, I prefer option 1 over option 2. However, option 1 may not be possible due to changes made in #1891.