Hi Andreas,

When your validator fails, you remain on the FormPage. A quick debug session shows me that the injected IService remains the same accross requests. The fix for your problem is simple, and a best practice anyway: inject Provider<EntityManager> in your service.

It's a best practice since the service does not know the "scope" of the entitymanager, all it knows is that the entitymanager has a different lifecycle; Your service may be instantiated and kept around for the time your app is running, but could also be instantiated on the fly when needed. That's one of the reasons why Provider<> was invented: if the scope is different, a provider allows you to nicely deal with it.

In case you are not familiar with providers: it has no negative side-effects in terms of performance. The guice-persist module binds the EntityManager per request, so all calls to Provider<EntityManager> while in the same request will yield the exact same EntityManager instance.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 27-6-2013 22:03, schreef Andreas Lundblad:
On Thu, Jun 27, 2013 at 3:59 PM, Bas Gooren <b...@iswd.nl> wrote:
I'm not the one who posed the original question.

Andreas, like I said: please show us some code, and we can help you pinpoint
your issue.

Thanks for all the rapid help!

I've created a minimal page that shows the error. Basically no
difference from the original code (
http://github.com/javadev/wicket-guice-demo )

To reproduce:

1. Download and unzip http://aoeu.se/www/wicketguice-problem.zip
2. mvn jetty:run
3. Go to localhost:9090, then go to "Form page"
4. Try to submit "gavin"
5. Try to submit "gavin" again.

This results in the 'EntityManager is closed' exception. No idea how
to solve this. If it's unsolvable, I'll look into the Provider
approach, but it would be really nice to manage without it.

best regards,
Andreas Lundblad

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


Reply via email to