You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
If a hibernate session has not yet been used for the current thread, and sessionFactory.currentSession is invoked, the tenant will not be honored. If Author.withSession { Session session -> } is invoked first, then sessionFactory.currentSession will honor the tenant.
Affected Versions
My issue was originally found in a Grails 5.x project, but given that Grails 6.x has been released, I reproduce it in Grails 6.x as well.
Sample project:
Generated a Grails 6 project, setup discriminator based multitenant config, added an Author domain class, create two Authors with opposite tenants in BootStrap, added service demonstrating the problem, and added a test case for service.
@jdaugherty IMO that's correct behavior, as sessionFactory.currentSession is returning non tenant, default sessionFactory.
If I correctly remember you should use sth like:
If the session is already initialized, sessionFactory returns a session that works as expected.
A Grails plugin / library that uses hibernate can unexpectedly expose this behavior.
Grails is built upon Spring Boot so existing code that is written for Spring usually works. In this case, non-Grails code could create a session and thus silently fail.
Hibernate documents how to create custom sessions. The GORM guide mentions the HibernateConnectionSourceFactory as how it creates a SessionFactory which implies that sessionFactory should work. This defect should at least be documented in the guide or be fixed to be consistent in Grails & non-Grails code.
Description:
If a hibernate session has not yet been used for the current thread, and
sessionFactory.currentSession
is invoked, the tenant will not be honored. IfAuthor.withSession { Session session -> }
is invoked first, thensessionFactory.currentSession
will honor the tenant.Affected Versions
My issue was originally found in a Grails 5.x project, but given that Grails 6.x has been released, I reproduce it in Grails 6.x as well.
Sample project:
Generated a Grails 6 project, setup discriminator based multitenant config, added an Author domain class, create two Authors with opposite tenants in BootStrap, added service demonstrating the problem, and added a test case for service.
https://github.com/jdaugherty/multitenant-issue
Run the integration tests to reproduce:
gradle integrationTest
The text was updated successfully, but these errors were encountered: