users@jpa-spec.java.net

[jpa-spec users] [jsr338-experts] Re: timing of when entity listeners (that reference CDI and a persistence unit) are registered...

From: Scott Marlow <smarlow_at_redhat.com>
Date: Thu, 23 Jan 2014 22:26:11 -0500

On 01/23/2014 09:19 AM, Scott Marlow wrote:
> Hi,
>
> I would like feedback on when entity listeners should be registered
> (during application deployment when
> PersistenceProvider.createContainerEntityManagerFactory() is called or
> later when the entity listener is about to be called for the first time).
>
> https://issues.jboss.org/browse/WFLY-2387 brings up a use case, where an
> entity listener
> (https://github.com/papegaaij/listener-injection/blob/master/inject-dao/src/main/java/nl/topicus/digdag/listener/ExcessiveLoadListener.java)
> references an entity manager.

Sorry, I left part of the use case out.

This use case is about entity listeners that use CDI injection and
reference the persistence unit. Or, entity listeners that use CDI
injection and indirectly reference the persistence unit via a CDI
injected bean.

The referenced persistence unit could be the same one that the entity
listener is associated with or a different one. The point being that if
all persistence providers, actually registered the entity listener
(lazily) when it is first needed, this CDI/JPA use case would work.

If the entity listener is registered before the persistence unit has
been created (e.g. we are still in the
PersistenceProvider.createContainerEntityManagerFactory()), references
to the persistence unit will not work.

The suggested change mentioned in WFLY-2387, is that persistence
providers defer registering the entity listener as long as possible
(e.g. until the application needs it).

I hope this is clearer.

>
> Whether its a self-reference, from creating the initial
> EntityManagerFactory, that references the entity listener, which in turn
> has a self reference back to the same persistence unit. Or, the entity
> listener references a different persistence unit. I don't think we have
> described this case as a JPA requirement. However, its not unreasonable
> that some applications might try to do this.
>
> Should we make it a (JPA) requirement that persistence providers defer
> registering the entity listener until the application needs to call one
> of the listener events?
>
> What do you think about allowing persistence providers to register
> entity listeners as late as on first application use?
>
> In the interest of standards, I would like to nail down whether we want
> to leave the requirements *open* in the future or agree on intent of
> what we want to do in the next spec release for this case.
>
> Scott