You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Kalle Korhonen <ka...@gmail.com> on 2012/03/14 18:49:31 UTC

A few questions regarding EntityManagerObjectProvider in JPA module

Hey Igor,

I was just looking into the implementation of the core JPA
integration. I had two questions about EntityManagerObjectProvider:
- what's the purpose of making a proxy for the EntityManager (rather
than just holding a reference to the EntityManager provided by the
EntityManagerManager)?
- does it not make sense to check if the proxy exists first and return
it right away before invoking the synchronized getOrCreateProxy?

My motivation for the questions is that I want to advise
EntityManager. Overriding EntityManagerObjectProvider seems like the
best place to do it.

Kalle

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: A few questions regarding EntityManagerObjectProvider in JPA module

Posted by Kalle Korhonen <ka...@gmail.com>.
On Thu, Mar 15, 2012 at 3:53 AM, Igor Drobiazko
<ig...@gmail.com> wrote:
> On Wed, Mar 14, 2012 at 6:49 PM, Kalle Korhonen
> <ka...@gmail.com>wrote:
>> - what's the purpose of making a proxy for the EntityManager (rather
>> than just holding a reference to the EntityManager provided by the
>> EntityManagerManager)?
> EntityManager is a per-thread resource which is managed by
> EntityManagerManager.
> You need a proxy if you want the injected object to be recreated for each
> request.

Igor, thanks for the confirmation, that's what I thought but didn't
quite see how creating the proxy alone was enough to make the
mechanism work.

>> - does it not make sense to check if the proxy exists first and return
>> it right away before invoking the synchronized getOrCreateProxy?
> You want to move the null check from getOrCreateProxy to provide or do you
> want to double check?

Well, once the proxy is created it won't be nullified until the end of
the request, so it seemed unnecessary to me to synchronize any access
to entityManager for all requests. So yes, double check, first
unsynchronized.

>> My motivation for the questions is that I want to advise
>> EntityManager. Overriding EntityManagerObjectProvider seems like the
>> best place to do it.
> Feels like pain in the ass.

Thanks, that sounds like a constructive approach for fostering innovation.

Kalle

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: A few questions regarding EntityManagerObjectProvider in JPA module

Posted by Igor Drobiazko <ig...@gmail.com>.
Hi Kalle,

On Wed, Mar 14, 2012 at 6:49 PM, Kalle Korhonen
<ka...@gmail.com>wrote:

> Hey Igor,
>
> I was just looking into the implementation of the core JPA
> integration. I had two questions about EntityManagerObjectProvider:
> - what's the purpose of making a proxy for the EntityManager (rather
> than just holding a reference to the EntityManager provided by the
> EntityManagerManager)?
>

EntityManager is a per-thread resource which is managed by
EntityManagerManager.
You need a proxy if you want the injected object to be recreated for each
request.


> - does it not make sense to check if the proxy exists first and return
> it right away before invoking the synchronized getOrCreateProxy?
>

You want to move the null check from getOrCreateProxy to provide or do you
want to double check?


>
> My motivation for the questions is that I want to advise
> EntityManager. Overriding EntityManagerObjectProvider seems like the
> best place to do it.
>

Feels like pain in the ass.


> Kalle
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de
http://twitter.com/drobiazko