users@glassfish.java.net

Re: How does Glassfish manage Persistence Contexts (equality tes

From: <forums_at_java.net>
Date: Fri, 18 Nov 2011 03:45:08 -0600 (CST)

Hello Mitesh!

> GlassFish uses a proxy/delegate pattern to propagate persistence
> context. That is a proxy is injected into components and the actual EM
> from provider is the delegate and is switched as required.

Thank you for claryfing this!
So it's the container responsible for scanning @PersistenceContext
annotations and for injection of the EntityManager, right? And it's the
container's design decision that it will use proxy to the actual JPA-provider
EM (like you've described it works in Glassfish) or if is not proxied?

> >Is there a way I can check two EntityManager instances for equality?
> >Can I do naive System.out.println(em) and check the value for
> PersistenceContexts equality?
> You can use EntityManager.getDelegate() to get to the actual delegate
> and compare. I am curious though about why you need to compare for
> persistence context equality

You're right, when I've read my post at loud I thought to myself that it's
quite weird why I would like to do such things :-)
I've described some rationale in my previous posts (in short: it's just for
learning/testing purpose and a way of getting a proof that another
PersistenceContext is used in certain situations).

By getting the delegate / unwrapping the EntityManager I can get access to
the underlying JPA-provider EntityManager.
So, assuming I have this actual JPA-provider EntityManager - can I be sure
(is it dictated by the spec?) that this object will be:
- equal across multiple calls within the same transaction and,
- different across multiple calls from different transactions?

Or perhaps the JPA provider is allowed to also do some proxying for his own
purpose and such comparison of the unwrapped EntityManagers is also futile.

> Regards,
> Mitesh
> Persistence module lead for GlassFish

Thanks a lot for your answer and time.

Regards,
Piotr


--
[Message sent by forum member 'PedroKowalski']
View Post: http://forums.java.net/node/865038