Refining the above answer instead of clearing the persistenceContext we simply evict the instances as we finish with them, like so.
Up vote 2 down vote favorite share g+ share fb share tw.
I'm missing something.... I have a Grails webflow that looks like this:- def childFlow = { start { action { def targets = Target.list(). Each {target -> targets. Add(new TargetCommand(name: target.
Name, id: target. Id)) } log. Debug "targets are $targets" children: targets } on('success').
To('selectChild') } ... TargetCommand is serializable. But I get this error:- Caused by: java.io. NotSerializableException: com.nerderg.groupie.donate.
Target For some reason the "target" object that is inside the Target.list(). Each {} closure is getting put into the flow scope, and I can't figure out how to mark it as transient. I have some code in a Service that has objects placed in the flow scope when I don't want them to too.
How do I stop local transient variables in closures being put in the flow scope? Grails spring-webflow link|improve this question edited Mar 1 at 10:59skaffman114k8136227 asked Nov 7 '09 at 3:15pmc907.
Actually the Target.list() is what puts the target ojects in the session and therefore the flow. – pmc Nov 7 '09 at 10:29.
Refining the above answer instead of clearing the persistenceContext we simply evict the instances as we finish with them, like so: Target.list(). Each { targets. Add(new TargetCommand(name: it.
Name, id: it. Id)) flow. PersistenceContext.
Evict(it) } This is still a work-around for not being able to mark the closure variables as transient.
The answer to my question is: the flow object is a map that contains a reference to the "persistenceContext" which is a org.hibernate.impl. SessionImpl so the flow tries to store the entire session, even if the objects are not changed (for context I suppose) this incorrect example from grails 1.1. X doc gives us a clue what to do: processPurchaseOrder { action { def a = flow. Address def p = flow.
Person def pd = flow. PaymentDetails def cartItems = flow. CartItems flow.clear() def o = new Order(person:p, shippingAddress:a, paymentDetails:pd) o.
InvoiceNumber = new Random(). NextInt(9999999) cartItems. Each { o.
AddToItems(it) } o.save() order:o } on("error"). To "confirmPurchase" on(Exception). To "confirmPurchase" on("success").
To "displayInvoice" } The flow.clear() clears the entire flow map including the persistenceContext or the session, which then makes the whole flow fail due to lack of a session. So the intermediate "solution" is to use the persistenceContext and in this case clear it. So this works:- def childFlow = { start { action { sponsorService.
UpdateTargetsFromTaggedContent() def targets = Target.list(). Each { targets. Add(new TargetCommand(name: it.
Name, id: it. Id)) } flow. PersistenceContext.clear() children: targets } on('success').
To('selectChild') on(Exception). To 'finish' } The obvious problem with this is that the session is cleared completely, instead of just keeping out things I don't want in the flow.
Thank you. I wasted an afternoon dumbfounded by this until I saw your answer. Very strange behaviour... not sure why the flow should be persisting the entire hibernate session by default, but clearing it works for me.
– Martin Dow Oct 25 '10 at 9:10 Very late in the day, but this is apparently done to ensure that conversations work. An alternative solution is to make any domain classes that might be accessed from within a flow Serializable. – Peter Ledbrook Nov 29 '10 at 13:43 I've raised an issue for this, by the way: jira.codehaus.org/browse/GRAILS-6984 – Martin Dow Nov 30 '10 at 16:56.
For want of a better way, here is a generalised solution that removes any non Serializable objects from the persistenceContext of the flow. This could be a service method given the flow:- def remove = flow. PersistenceContext.
GetPersistenceContext(). GetEntitiesByKey().values(). Each { entity -> if(!entity instanceof Serializable){ remove.
Add(entity) } } remove. Each {flow. PersistenceContext.
Evict(it)}.
Which is all good and fine till you use a tag in the view that selects a domain object. I'm thinking either webflow isn't made for this or it's a braindead impl – pmc Nov 7 '09 at 10:45 fixed the tag issue by implementing a new tag that calls flowService. CleanUpSession(flow) - e.g. – pmc Nov 7 '09 at 11:15 Note this seems to only work in the first state action.
Other things that seem to work is to detach the domain object in question. If all elese fails implement serializable :-/ – pmc Nov 16 '09 at 2:35.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.