Frank,
Regarding your question (without joining the IOC holy-war), your experience
seems odd.  The wicket rad project has examples of this approach and from
memory there are some slides from a wicket presentation in London on the
same thing floating about so I think we can conclude it is a common
approach.

I actually like this approach and given that the wicket guys gave us the
request cycle and such an easy way to implement our own, it seems a very
"wicket" way to handle the problem as long as it fits your use case (all
transactions inside the request).

A couple of general thoughts - apologies if these are too basic.

- Are you sure your Entity manager is being opened correctly and set in the
threadlocal in onBeginRequest.  If you are putting it in there correctly,
the only way it is coming out is if you take it out.

- Any chance the same entity manager is getting closed somewhere else in the
code.

- Are you setting your entity manager on the threadlocal during
onBeginRequest by putting it on or relying on the inititalvalue for the
threadlocal.  This is only called once per thread on the first get.  As
threads are re-used, only the first requestcycle using a thread will call
this.

- Are you over-riding onRuntimeException as well as onEndRequest and
handling the threadlocal cleanup in both places.

- Leaving entity managers lying around doesn't seem ideal.  I think it is
better to clean them up and rely on pooling.  Using dbcp with Apache openJpa
gives a spectacular speedup.

As above, apologies if this is all too basic, just brain dumping before bed
time.

Cheers,

Adrian,
Auckland, NZ.

On Tue, Jun 9, 2009 at 11:48 PM, Frank Tegtmeyer <f...@fte.to> wrote:

>
> > Well when it comes to EntityManagers be sure to close, commit and
> > clear your threadlocal instance after your service request cycle.
>
> Exactly that didn't work for me. I checked for open transactions,
> closed them, closed the EntityManager and even released it by setting
> the ThreadLocal variable to null.
> Although I created a new EntityManager  in onBeginRequest() I
> constantly got errors during form processing because of not existing
> EntityManager. I solved this by leaving EntityManager there after the
> request and checking for its existence at the begin of the request.
>
> Any ideas about this?
>
> Regards, Frank
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to