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. |