borinquenkid opened a new issue, #16783:
URL: https://github.com/apache/grails-core/issues/16783

   ### Expected Behavior
   
   In a Grails 7 application with Hibernate 5, after `withNewSession { 
withTransaction { … } }` completes, the OSIV-bound request session should 
remain usable for subsequent queries and operations.
   
   ### Actual Behaviour
   
   When an initial transaction ends on the request session, Spring disconnects 
the session's physical JDBC connection. If the application subsequently calls 
`withNewSession { withTransaction { ... } }` and touches a lazy association of 
an entity loaded by the outer request session, the outer session requests a 
connection from the DataSource and borrows the inner transaction's thread-bound 
connection.
   
   When the inner transaction completes, it closes that connection, leaving the 
outer session holding a closed connection. Subsequent operations on the outer 
session fail with:
   ```
   org.springframework.dao.DataAccessException: ... PooledConnection has 
already been closed
   ```
   
   Additionally, under `PROPAGATION_SUPPORTS` transaction scopes containing 
nested `withNewSession` invocations without an in-scope query on the outer 
session, connection synchronization can close the outer session connection upon 
scope completion.
   
   ### Steps To Reproduce
   
   ```groovy
   Book book = Book.first()
   Author.withTransaction { Author.count() } // ends transaction, disconnects 
request session
   
   Book.withNewSession {
       Book.withTransaction {
           book.author.name // lazy load through the request session borrows 
inner connection
           new Author(name: 'Tenar').save()
       }
   }
   Book.count() // fails: connection is closed
   ```
   
   ### Environment Information
   
   - Grails 7.0.x
   - Hibernate ORM 5.6
   - Spring Framework 6.2
   - Groovy 4.0
   - JDK 17 / 21


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

Reply via email to