Grails Webflow : Error could not initialize proxy - no Session when trying to access a domain set in PageScope

做~自己de王妃 提交于 2019-12-02 06:17:34

问题


We have a custom tag similar to g:set which sets the current user into PageScope <n:currentUser var=”foobar”> It works great until we have a flowaction.

For a flowaction view state, which uses above tag, it will throw Lazy initialization exception “could not initialize proxy - no Session”, even though the user is loaded in the same request and set in pagescope.

Doesn’t webflow respect OpenSessionInView ! What’s going wrong here. What could be the solution other then eager fetching and passing the modal explicitly.

(The tag is in a layout actually, which is applied for the view of the view state)

UPDATE

I just noticed, that even when accessing the the object right after it is loaded, it still gives the same error. So its not PageScope things causing the issue

Inside the tag

User user = User.get(x)
println user.foo.bar gives the same error

It looks like, for flow actions, session isn't kept open at all, and it seems to close right after the operation is complete.

Thanks


回答1:


I've seen this error before, and not related to the webflow, but using a tag inside a layout. In this case the layout is handled after the session is closed and you need to create a new session manually.

def currentUser = { attrs ->
  User.withTransaction {
    User user = User.get(x)
  }
}

The JIRA have the status won't fix because is not a good practice to make GORM queries inside TagLib's.



来源:https://stackoverflow.com/questions/21456784/grails-webflow-error-could-not-initialize-proxy-no-session-when-trying-to-ac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!