I recently migrated a multi-module application from Grails 6 to Grails 7.0.1 and am facing a MongoDB lazy-loading issue during GSP rendering.
Project structure:
Main Application
- Module 1 (contains MongoDB domain classes such as Test, Test1, etc.)
- Module 2 (uses domain classes from Module 1)
In a GSP page, I have something like:
test1 class is a Foreign Key(FK) in test class
<g:each in="${testList}" var="test">
<option value="${test.id}">
${test?.test1?.name}
</option>
</g:each>
After migrating to Grails 7, the page throws the following error:
No datastore session found. Call Datastore.connect(..) before calling Datastore.getCurrentSession().
Interestingly, if I access the association in the controller before rendering the GSP, or if I convert the data to DTOs/maps and pass that to the view, the page works correctly.
- Has datastore session handling during GSP rendering changed in Grails 7 compared to Grails 6?
- Is there a recommended global solution for this issue instead of manually initializing associations or creating DTOs for every page?
- Has anyone faced similar issues in multi-module Grails 7 applications using MongoDB references?
I recently migrated a multi-module application from Grails 6 to Grails 7.0.1 and am facing a MongoDB lazy-loading issue during GSP rendering.
Project structure:
Main Application
In a GSP page, I have something like:
test1 class is a Foreign Key(FK) in test class
After migrating to Grails 7, the page throws the following error:
No datastore session found. Call Datastore.connect(..) before calling Datastore.getCurrentSession().Interestingly, if I access the association in the controller before rendering the GSP, or if I convert the data to DTOs/maps and pass that to the view, the page works correctly.