[cdi-dev] Fwd: [jsr338-experts] Integration of EntityListeners Classes with CDI (Java EE 7)

Pete Muir pmuir at bleepbleep.org.uk
Tue Jun 21 10:11:27 EDT 2011


On 21 Jun 2011, at 15:07, Jens Schumann wrote:

> Pete:
> 
>> Instead, I would propose that EntityListeners are simply added to
>> the list of Java EE components which are able to be injected. This
>> means they can be injected, but are not available for injection into
>> other components.
> 
> 
> Maybe I don't understand this because I am not a native English speaker;).
> 
> Will your proposal support something like this:
> 
> public class ModificationListener {
> 
> @Inject
> @Current
> private User user;
> 
> @PrePersist
> public void onCreate(Object obj) {
>  if (obj instanceof ModifiableObject) {
>    // make use of current user
>  }
> }
> }
> 

Yes, it would allow exactly this. What it won't allow is the converse:

class User {

   @Inject ModificationListener listener

   ...

}

As I don't believe this has any meaning :-)

In Java EE spec speak, we can achieve this by making EntityListener a Java EE component (as a side effect, this would also allow @Resource and @EJB injection).


> Right now I have use the BeanManager within the listener to achieve the
> same result. Pretty inconvenient.

Exactly.


More information about the cdi-dev mailing list