RAJ-debug858 opened a new pull request, #15002:
URL: https://github.com/apache/grails-core/pull/15002

   I've successfully implemented a solution to address the Hibernate session 
and transaction issue in Grails
     integration tests. The solution provides a way for integration tests to 
run with the same transactional context      
     as the application.
   
     What was implemented:
   
     1. @WithSession annotation
     
(grails-testing-support-core/src/main/groovy/grails/testing/mixin/integration/WithSession.groovy):
       - New annotation that binds a Hibernate session without starting a 
transaction
       - Can be applied at class or method level
       - Supports specifying specific datasources
     2. Session binding infrastructure:
       - GrailsTestSessionInterceptor - Manages session binding without 
transactions
       - WithSessionSpecExtension - Spock extension for handling @WithSession
       - WithSessionTransformation - AST transformation for the annotation
     3. Enhanced test infrastructure:
       - Updated GrailsTestMode to support bindSession flag
       - Modified GrailsTestInterceptor to handle session-only binding
       - Updated IntegrationSpecConfigurerExtension to enable session binding 
by default
     4. Test examples:
       - WithSessionIntegrationSpec - Demonstrates usage of @WithSession
       - SessionBindingComparisonSpec - Shows differences between test modes
     5. Documentation:
       - Added comprehensive documentation in the integration testing guide
   
     How it solves the problem:
   
     The issue described three scenarios:
     - Without @Rollback: No session bound → tests fail for operations that 
work in the app
     - With @Rollback: Both session and transaction → tests pass for operations 
that fail in the app
     - With @WithSession: Session without transaction → tests match application 
behavior
   
     The new @WithSession annotation provides a session binding that matches 
the OISV (Open Session In View) pattern      
     used in running applications, where:
     - SELECT operations work (session available)
     - save() without flush works (no transaction needed)
     - save(flush: true) fails without @Transactional (matches runtime behavior)
   
     This ensures integration tests accurately reflect the application's 
runtime behavior, preventing false positives     
      and false negatives in test results.


-- 
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: notifications-unsubscr...@grails.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to