Issue Type: Bug Bug
Affects Versions: 4.1.8, 4.1.7, 4.1.6, 4.1.5.SP1
Assignee: Unassigned
Attachments: hibernate-one-to-one-defect_4.1.7.zip, hibernate-one-to-one-defect_4.1.8.zip
Components: core
Created: 27/Nov/12 9:29 AM
Description:

When having an inverse one-to-one bi-directional associations between two entities with orphan removal enabled Hibernate throws a NullPointerExceptions under the following conditions:

  • The bidirectional references are nulled out.
  • A manual flush is performed during the transaction.

The NullPointerException is raised in the Cascade.cascadeProperty method on performing the flush on commit of the transaction. The problem is that the code tries to retrieve the EntityEntry for the referenced entity and tries to lookup the entity name for it (see Cascade.java:256ff):

final EntityEntry valueEntry = eventSource.getPersistenceContext().getEntry(loadedValue );
final String entityName = valueEntry.getPersister().getEntityName();

Resolving the entity name fails as the valueEntry is null during the second flush on commit of the transaction. The entity entry has already discarded during the manual flush.

This defect is a relic of fix for issue HHH-5267, which works if you only perform a single flush during the lifecycle of a single entity manager/session.

In versions prior to 4.1.8 (i.e. before fix HHH-5267) the problem was throwing a org.hibernate.PropertyAccessException since it was using the wrong entity name for delete cascading.

I have attached two test cases show casing the error situations caused by the manual flush on these one-to-one associations.
Code wise the test cases are exactly the same but one case uses Hibernate 4.1.8 and the other one 4.1.7.

Environment: Hibernate 4.1.8
DB Platforms tested: Oracle, H2
Project: Hibernate ORM
Labels: core one-to-one orphan-removal
Priority: Major Major
Reporter: Denis Pasek
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira