Loading a polymorphic entity with outer joins can cause exception if subclasses have collections

Description

Steps to recreate..

1) Create a polymorhpic entity mapping using table-per-hierarchy strategy. We'll call this type "Parent"

2) Add one subclass element that does not contain any collection properties. We'll call this type "ChildA"

3) Add a second subclass that contains at least one collection property that is set to cascade="all-delete-orphan". We'll call this "ChildB"

4) Configure the hibernate properties to have a max-fetch-depth >= 2 so that it will perform outer joins.

4) load an instance of "ChildA" inside a transaction using session.load(Parent.class, someId);, where someId points to an instance of "ChildA".

5) commit and close the transaction.

6) you should recieve a hibernate exception "Can not dereference a collection marked cascade="all-delete-orpha"

Whats happened is that during the load process when hibernate is trying to figure out what type we are loading it creates a collection for the subclass that we didn't actually load. Then durring commit it thinks this collection has been dereferenced.

Environment

Hibernate 2.1.8, Microsoft SQL Server 200 sp3, Windows 2003, Java 1.4.2_02

Assignee

Unassigned

Reporter

RoyR

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Affects versions

Priority

Major
Configure