Hi,
I even got an email with another request for integration of EntityListeners and CDI:
From: Craig Ringer <craig_at_postnewspapers.com.au>
(...)
Having read over the JPA 2.1 proposal, I'm concerned to see no mention
of integration with dependency injection systems like JSR 299 (CDI) or
lifecycle hooks to enable such integration.
Right now, one of the big and frustrating problems with building Java EE
6 web applications is that the dependency injection mechanism
standardized by EJB 3.1 and CDI doesn't function within the context of
JPA entities and EntityListeners. This makes JPA 2.0 an extremely
frustrating environment to work in, because the managed bean environment
and managed contexts are unavailable.
CDI is rapidly becoming the default programming model for Java EE 6 web
applications. It's been supported since Glassfish 3.0 and will be
included JBoss AS 7 as well, though it's already optional in AS 6. It is
not an area that the JPA spec can afford to ignore.
CDI is already integrated into other core technologies in the Java EE 6
environment like JAX-RS and JavaServer Faces 2.
To work around the lack of DI integration in the JPA 2.0 spec,
developers must currently rely on a servlet filter like that provided by
Seam 3 Solder, combined with helper classes like BeanManagerLocator
(from Seam 3 Solder) that are ugly in the extreme, prone to leaks, and
result in verbose, messy code.
I would be delighted if the WG considered adding DI integration
requirements to the JPA 2.1 spec. The single most important thing to do
is instantiate EntityListeners and simiar helpers via standardized,
hookable factories that may be intercepted by DI frameworks like JSR299
(CDI), Google Guice, Spring Framework, etc. Supporting hookable
lifecycle events for entity beans would be a big help too. More about
this can be learned from the documentation for the JSR299 reference
implementation, Weld:
http://docs.jboss.org/weld/reference/latest/en-US/html/extend.html
http://seamframework.org/Weld/Development
https://lists.jboss.org/mailman/listinfo/weld-dev
Examples of how to support dependency injection integration may be found
in the JavaServer Faces 2 and JAX-RS environments.
The Seam 3 Faces module provides a demonstration of how a spec and
implementation need not directly depend on DI, only provide appropriate
hooks. Seam 3 Faces adds DI support and lifecycle management to
@FacesConverter and other JavaServer Faces helpers that were previously
much like EntityListeners.
--
Craig Ringer