gbadner/hibernate-core — comment on commit d62ad40fda8cf9c5eadd7fbe39317383c6c917d6
File: hibernate-core/src/main/java/org/hibernate/action/internal/UnresolvedEntityInsertActions.java line 194
By gbadner:

The current behavior (before this proposed change) is kind of complicated when an entity has a non-nullable, transient reference that is not resolved by cascading.

When CHECK_NULLABILITY is true:
1) save event listener will throw PropertyValueException;
2) merge event listener will throw TransientObjectException; I chose to throw TransientObjectException from the merge retry code, when Hibernate knew it was due to a non-nullable, transient entity reference. In retrospect, this should have been left as PropertyValueException.

When CHECK_NULLABILITY is false:
1) if the entity insert action is executed before the session is flushed (i.e., an "early" insert to generate an identity ID), then JDBCException is thrown;
2) otherwise, TransientObjectException is thrown when the owning entity is dirty-checked.

The proposed change would make the behavior consistent for all of these caes. If there are any "unresolved" non-nullable, transient entities after the top-level save/merge event executes, then TransientObjectException would be thrown, regardless of the CHECK_NULLABILITY setting.

I am also leary about making changes to the exception handling at this stage for 4.0.1. The behavior should definitely be made consistent for 4.1, throwing PropertyValueException instead of TransientObjectException. This will be done for HHH-6744 as an improvement.

I'll restore the original (complicated) behavior and create a pull request for HHH-6744 to make things consistent. It *should* be a small change.