Skip to content

Cannot instantiate a SessionFactory using Prevalence cache #2190

Closed
@deAtog

Description

@deAtog

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:

  1. Do not serialize the SessionFactory as part of the cache key. This is the approach taken by Hibernate ORM.
  2. 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 calling SessionFactoryObjectFactory.GetNamedInstance.

Personally, I prefer option 1 over option 2. However, option 1 may not be possible due to changes made in #1891.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions