Cascaded evictions fail when same entity referenced multiple times

Description

IllegalArgumentException "Non-entity object instance passed to evict" is thrown when an entity that (directly or indirectly) references the same entity multiple times.

For example this occurs with mappings (see attached test case also):

<hibernate-mapping>
<class entity-name="A" name="com.cyclone.hibernate.A">
<id name="id" access="field" />
<many-to-one name="b1" entity-name="B" cascade="all" />
<many-to-one name="b2" entity-name="B" cascade="all" />
</class>
<class entity-name="B" name="com.cyclone.hibernate.B">
<id name="id" access="field" />
</class>
</hibernate-mapping>

when a single A entity has both b1 and b2 set to the same B instance and A is evicted from the session.

Happens with code added for which fails to get a persister the second time DefaultEvictEventListener.onEvict(...) is called for the B entity because the (guessed) entity name is the class name, and not the entity name defined in the mappings.

Environment

None

Assignee

Unassigned

Reporter

Jeremy Stone

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure