Question

I have an entity:-

@Entity
@Table
public class Application{

@Inject
@QualifierName
private Event<Application> applicationXXX;

public void someMethod(){
 applicationXXX.fire(someObject);
}
//BODY
} 

In MyEventhandler Class , I'm using :

public void onXXX(@Observes @QualifierName Object someObject){

}

the injection in Application class for Event --- applicationXXX is null.

however the same injection if i do in some other class then it's not null and working.

can any one help me and point out what I'm missing here ???

can't i inject CDI events in Entity ??? or is there any other method ???

Thanks

Was it helpful?

Solution

JPA entities are special, because they're already under management from JPA you need to have producer for them, even then I really doubt the injection would still work. I suggest not using CDI concepts within JPA entities.

For this case I'd call some other middle man class to handle the event firing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top