Re: Prettyfaces + Hibernate + Spring lazy initialization

Splash Forums PrettyFaces Users Prettyfaces + Hibernate + Spring lazy initialization Re: Prettyfaces + Hibernate + Spring lazy initialization

#22551

This sound like you are calling an action method to “prepare” the edit page by loading the corresponding object from the database, then doing return "pretty: edit"; which redirects the user to the actual edit page. Correct?

In this case the exception is easy to explain. You are first loading the object and then you do a redirect. After the redirect the object will be detached resulting in a lazy initialization exception because the redirect results in a new request to the server.

This is a pattern that is not recommended. You should instead encode the ID of the object you want to edit in the URL. Then load the object in an URL action. This way you get a clean bookmarkable URL like /user/edit/5.

The example 3.1 in this chapter of the documentation:

http://ocpsoft.org/docs/prettyfaces/3.3.2/en-US/html/Configuration.html#config.actions

I hope this helps :)

Christian