Thanks for the quick LDEV-6941 fix. 5.6.15.23 fixes the split on our bench (ORM work and queryExecute() now share the transaction’s connection after a save/reload/flush outside a block), and LDEV-6935 recovery works too.
The new version introduces one regression:
t = entityLoad( "AccountTransaction", {}, "", { maxresults: 1 } )[ 1 ]; // outside any transaction
transaction {
t.getAccount().getBalance(); // lazy many-to-one, first ORM read in the block
}
On 5.6.15.23 (Lucee 6.2.10.1-SNAPSHOT, Java 21, MySQL 8.0, Connector/J 9.7.0) this throws:
org.hibernate.exception.GenericJDBCException: Could not read entity state from ResultSet : EntityKey\[Account#...\]
Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.cj.jdbc.result.ResultSetImpl.checkClosed
at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.loadFromResultSet
at org.hibernate.proxy.AbstractLazyInitializer.initialize
at org.lucee.extension.orm.hibernate.tuplizer.proxy.CFCLazyInitializer.getCFC
5.6.15.21 and Ortus 6.5.4 run it fine.
It also fails after a queryExecute() at the top of the block, and with entityLoadByPK( “Account”, t.getAccount().getId() ), because getId() on the CFC proxy already initializes it. It passes if another ORM function (entityLoadByPK() of a different entity) runs first inside the block.
Traced with HibernateORMTransaction 5.6.15.23 plus logging in begin(). On the failing request the call path is:
CFCLazyInitializer.getCFC -> SessionImpl.immediateLoad -> (SELECT runs, ResultSet open)
-> EntityReferenceInitializerImpl.hydrateEntityState -> CFCInstantiator.instantiate (line 62)
-> HibernateUtil.getORMSession -> PageContextImpl.getORMSession -> DatasourceManagerImpl.add
-> ORMConnection.<init> -> HibernateORMTransaction.begin() -> releaseHeldConnection()
At that point the session reports isTransactionInProgress()=false, isPhysicallyConnected()=true and getResourceRegistry().hasRegisteredResources()=true. jdbc.afterTransaction() releases the registry, which closes the ResultSet the load is still reading. So the connection being released is not one held from work outside the block; it is the one the proxy load just opened. The first ORM touch inside the cftransaction happens during hydration (CFCInstantiator asks for the ORM session), and that is what creates the ORMConnection and calls begin().
When a Lucee ORM function runs first in the block (entityLoad, entityLoadByPK → ORMUtil.getSession), begin() runs before any SQL with physicallyConnected=false, and everything works. A lazy one-to-many collection initialized first in the block fails the same way (PersistentBag.size → AbstractPersistentCollection.initialize → … → CFCInstantiator.instantiate → begin()).
We haven’t tried a fix. Simply skipping the release when the registry has open resources would avoid the error but leave that block’s ORM work on the connection the load opened, which looks like the LDEV-6941 split again, so the right guard may be about when begin() runs rather than whether to release.
This is a common shape for the app I’m working on (controllers load an entity, then open a transaction and touch its associations), so it’s a blocker. I’m more than happy to test a build when you have one.