IllegalArgumentException: Non-entity object instance passed to evict - happens when using entity-names and XML

Description

In some cases evicting a transient entity gives: java.lang.IllegalArgumentException: Non-entity object instance passed to evict

I'm aware of several Hibernate issues covering this, and I'm also aware that some of the eviction rules changed due to JPA2.1 spec. However, the behavior seen here is inconsistent: when using XML mapping files and using the entity-name attribute on the class mapping, this exception seems to appear when the parent of a one-to-many is evicted while one of it's children is not yet persisted. When using the exact same example, but instead not using entity-name (and thus referring to the entity using it's class name) the eviction seems to work without a problem.

Please see the attached example project/test case.

Summary from the attached test case:

Given this mapping:

mapping.hbm.xml

The following test case wil fail due to :java.lang.IllegalArgumentException: Non-entity object instance passed to evict : be.test.Child

EvictTest.java

If we now alter the mapping file but use class instead of entity-name:

mapping.hbm.xml

The same test case does work.

Environment

Hibernate 4.3.3
Java 7

Assignee

Unassigned

Reporter

Koen Serneels

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure