Sudhir N
Sudhir N

Reputation: 4096

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

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

Upvotes: 2

Views: 2104

Answers (1)

user800014
user800014

Reputation:

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.

Upvotes: 1

Related Questions