Skip to main content

[jsr338-experts] injection into entity listeners

  • From: Linda DeMichiel <linda.demichiel@oracle.com>
  • To: jsr338-experts@jpa-spec.java.net
  • Subject: [jsr338-experts] injection into entity listeners
  • Date: Wed, 20 Jul 2011 12:51:46 -0700
  • Organization: Oracle Corporation

Greetings,

We've gotten a number of requests for supporting CDI injection
into entity listeners.   I've been doing some iterating behind the
scenes with Emmanuel and Pete Muir as to how we might address
this.

Pete pointed out the CDI SPIs which the persistence provider could use
to make this work.  Please see the following item in the Seam FAQ,
http://seamframework.org/Documentation/HowDoIDoNoncontextualInjectionForAThirdpartyFramework

This approach looks fairly straightforward and involves direct
interaction on the part of the persistence provider with the CDI
implementation.  The entry point for this interaction is the CDI
BeanManager, which the persistence provider can obtain from the Java
EE container in JNDI as java:comp/BeanManager.  Using the CDI SPIs,
the persistence provider interacts with CDI to obtain instances of
entity listener classes upon which CDI has performed injection.

I'd therefore like propose the following additions to the JPA spec:

*  An entity listener class may be defined for CDI injection.
   A listener class that is intended to receive CDI injection must
   be annotated with the @BeanListener annotation (final annotation
   name TBD).

*  An entity listener class that is defined as a @BeanListener
   may specify PostConstruct and PreDestroy methods.  These methods
   will be invoked by the provider after injection has taken
   place and before the entity listener instance is destroyed respectively.

*  The persistence provider is only required to support CDI
   injection into listeners in Java EE container environments
   where the BeanManager is available in JNDI as java:comp/BeanManager.
   When this is not the case, @BeanListener classes will be
   ignored.

The implementation referenced above is a strategy the persistence
provider could use to implement this functionality, however, the
spec would not prescribe any particular implementation.

Finally, just to be very clear about this, an entity listener
would thus be, in CDI terminology, an "unmanaged object".
In other words, it would receive CDI injections, would not itself
be available for injection into other CDI-managed beans.

Comments?

-Linda


[jsr338-experts] injection into entity listeners

Linda DeMichiel 07/20/2011

[jsr338-experts] Re: injection into entity listeners

Gordon Yorke 07/20/2011

[jsr338-experts] Re: injection into entity listeners

Linda DeMichiel 07/20/2011

[jsr338-experts] Re: injection into entity listeners

Emmanuel Bernard 07/29/2011

[jsr338-experts] Re: injection into entity listeners

Linda DeMichiel 07/29/2011
 
 
Close
loading
Please Confirm
Close