Rahul Razdan
Rahul Razdan

Reputation: 429

CDI Event Injection in Entity is null , why?

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

Upvotes: 2

Views: 341

Answers (1)

LightGuard
LightGuard

Reputation: 5378

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.

Upvotes: 4

Related Questions