TransactionRequiredException should be thrown when early insert is required and hibernate.allow_update_outside_transaction=false

Description

In AbstractSaveEventListener, Hibernate may not do the right thing when: !isPartOfTransaction( source ) && requiresImmediateIdAccess.

shouldDelayIdentityInserts will be set to false, and Hibernate will perform the insert (using auto-commit?), even if hibernate.allow_update_outside_transaction=false (the default).

If hibernate.allow_update_outside_transaction=false, TransactionRequiredException should be thrown.

I'll address #isPartOfTransaction below.

Background (as I understand it):

IIUC, Hibernate requires that the entity have an ID when Session#save (which returns the ID) or Session#saveOrUpdate is used to persist a transient entity, so requiresImmediateIdAccess == true in those cases.

Session#persist does not require that the entity have an ID until after flush so requiresImmediateIdAccess == false in that case.

Environment

None

Assignee

Unassigned

Reporter

Gail Badner

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure