Skip to content

One-to-one with property-ref triggers StackOverflow Exception #1645

Closed
@michaelestermann

Description

@michaelestermann

When we updated our project to the latest version of NHibernate (5.1), we run into a Stackoverflow exception. After some investigation, we were able to reproduce the behavior in a small project.

The structure of the database looks as following:
[SuperParent] <-- 1:1 --> [Parent] <-- 1:n --> [Child]

To end up in the exception, two requirements must be given:

  • Parent must have a back reference to its "super parent"
  • Parent must override equals

The change which introduced this misbehavior is in the Loader class (Line 953). When getting a row, it caches the the loaded entity now. The caching uses the GetHashCode method of the entity to create a unique key. If the entity is not initialized yet, it starts to load the entity again. When loading the same entity again, the entity is still not initialized (AbstractLazyInitializer.Initialize() on line 107) and it ends up again in caching the same entity.

The repro can be found here: https://github.com/michaelestermann/NHibernateRepro

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions