Skip to content

Grails 7 - MongoDB Lazy Loading Issue in GSP #15707

@low-he-th

Description

@low-he-th

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.

  1. Has datastore session handling during GSP rendering changed in Grails 7 compared to Grails 6?
  2. Is there a recommended global solution for this issue instead of manually initializing associations or creating DTOs for every page?
  3. Has anyone faced similar issues in multi-module Grails 7 applications using MongoDB references?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions