jamesfredley commented on PR #15731:
URL: https://github.com/apache/grails-core/pull/15731#issuecomment-4733002704
## Fixed: non-transactional BootStrap saves silently discarded on Hibernate 7
Investigated the scaffolding-fields-on-H7 failures and found a real
Hibernate 7 framework regression. New commits: `7a6cc6375f` (fix + test),
`6ae130adb5` (review-comment: simplified the `ChainedTransactionManager` dedupe
comment).
### Root cause (runtime-traced)
A `@Integration` clone of `scaffolding-fields` showed bootstrap-seeded data
missing from scaffolded relationship forms. Instrumenting `BootStrap` proved
that GORM `.save()` calls in a **non-transactional** `init` closure did not
persist on H7 (`Department.count() == 0` immediately after seeding), while a
`withTransaction {}` probe committed them.
`GrailsConfigUtils.executeGrailsBootstraps` binds a session via the
`PersistenceContextInterceptor` (`init()`), runs the BootStrap closures, then
calls `interceptor.flush()` / `destroy()`. On H7,
`HibernatePersistenceContextInterceptor.flush()` was a **no-op** for this path:
its constructor hardcodes `transactionRequired = true`, and `flush()` only
flushed when `TransactionSynchronizationManager.isSynchronizationActive()` -
which is `false` during a non-transactional BootStrap. So the interceptor-owned
session was never flushed/committed and `destroy()` discarded the pending
inserts. (H5 happened to persist them.)
### Fix
`HibernatePersistenceContextInterceptor.flush()` now, when it is not
participating in an outer session and there is no active synchronization (it
opened the session itself, e.g. for a non-transactional BootStrap), flushes
**and commits** the owned session's pending changes in a short transaction. The
existing non-transactional and active-synchronization branches (the OSIV
web-request path) are unchanged. Locked with a
`HibernatePersistenceContextInterceptorSpec` regression test mirroring the
BootStrap flow.
### Verification
- `HibernatePersistenceContextInterceptorSpec`: 4/4 (3 existing + the new
test).
- H7 `scaffolding-fields` functional app: **123/136 -> 134/136** (all the
bootstrap-data relationship failures resolved).
- H7 `views-functional-tests`: still **52/52** (OSIV not regressed).
The 2 residual scaffolding failures are Geb test-stability issues, not H7
regressions: a flaky sort/list interaction (a different pagination spec fails
on each run) and a show-page belongsTo display assertion (body captured before
content renders). Tables above updated; the second-level-cache question is
answered inline (covered by `SecondLevelCacheSpec`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]