NullPointerException when manually flushing One-To-One relationship with orphan removal

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.

Attachments

2
  • 27 Nov 2012, 05:29 PM
  • 27 Nov 2012, 05:29 PM

Activity

Show:

Brett MeyerFebruary 1, 2013 at 10:44 PM

Np. We're waiting on Javassist to fix an issue they caused in their latest release before we do 4.1.0.Final. Hopefully soon...

Denis PasekFebruary 1, 2013 at 10:40 PM

Hi Brett,

thanks for fixing it.

Is there already a release date for 4.1.10? According to the roadmap it should have been release in January butthis date has already passed.
Currently we use a patched version of 4.1.5.SP1 in production but would like to switch to an official release in the next release of the web application (somewhere in March).

Funnily my patch looks very familiar to your commit from today winking face

Brett MeyerFebruary 1, 2013 at 8:01 PM

Thanks for the great description and test case – good catch.

Denis PasekNovember 27, 2012 at 5:40 PM

Against prior assumptions this error and the change in the error behavior for from 4.1.7 to 4.1.8 release was caused by fixes for https://hibernate.atlassian.net/browse/HHH-7359#icft=HHH-7359 caused by the following commit:
https://github.com/hibernate/hibernate-orm/commit/deaff9705e564b33b92b3eac9fdee89815ce1a44

Parts of this error also are covered in HHH-7821.

Fixed

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Created November 27, 2012 at 5:29 PM
Updated March 23, 2017 at 8:38 PM
Resolved February 1, 2013 at 8:01 PM

Flag notifications