Grails: 404 and lazy initialization

If you go to a page that doesn’t exist, but 404 is “thrown” and Grails tries to display my 404 error page, I get lazy initialization errors from some taglib tags that I have that run in the error layout.

Taglib is really trying to access a domain object inside another domain object, which is a has-many relationship. It can get the initial object, but when accessing this connection, it generates this lazy initialization error.

However, this does not happen when any other page is accessed correctly. Even if I try to access my error page directly. Only with 404 error.

Is there anything else in the hibernate session during this time that causes a lazy initialization error?

Is it possible that accessing what is lazily initialized in taglib is not a good idea in Grails?

+3
source share
1 answer

I have seen this before, and my usual solution would be to transfer the request to the controller. I believe this is because the controller and GSP sessions are not the same - hence it is a good idea to do most database reads in the controller.

In this case, the controller is missing.

As for hacks, to get around this problem ...

, / GSP / taglib, , , () - .

+2

Source: https://habr.com/ru/post/1786231/


All Articles