This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

FYI: OpenSessionInView, LazyInitializationException, and Flow scope form objectsPage Title Module

I offer this post more as a how-to than a request for help, but if you know of a better way, do share:

I had a persisted object that I was keeping in the Flow Scope because I needed to manipulate different parts on different requests. The problem I faced is that in a subsequent request when I need to maninpulate the Set my persisted object contained I would encounter an LazyInitializationException (LIE) due to the Session being closed, even though I had been using the OpenSessionInViewFilter (OSIV).

Even though I was using the OSIV and had a Session, that didn't mean that my object would "know" to use that Session to complete its lazy initialization.

So, I had to reattach the object, and this is how I did it: FlowExecutionListener

Comment

Just to add to what your saying Daniel. You beat me to the punch I myself had a similar issue when my subflows were serialized and then deserialized. Your persistent Set (See hinerate PersistentSet or its superclass), upon serialization, losses the current session, since it is declared as transient. Therefore, there is an explicit need to reattach your object to the current session, especially objects that have collections, like Sets.

Using a FlowExecutionListener is a good option. I have not done so, but I am thinking I should. What I did was to refresh my object (doing a LockMode.READ), thus associating to the currernt session, just when I am about to update it. I do a LockMode.READ because I want to bypass the secondary cache and force a database read (don't want stale data). I like the manual approach, but the downside (perhaps a downside) it forces you to be aware of your persistent object state.