Inject EJB into domain object with Java EE 6

cdi, domain-driven-design, ejb, jakarta-ee, java-ee-6

Solution

In Java EE 6, CDI extends the concept of managed component to anything and EJB can be injected into a CDI managed bean (using the `@Inject` annotation). But while interaction between JPA and CDI has been considered, this has not been made part of the Java EE 6 specification(s). In other words, injection into a JPA entity is not possible.

See also

- CDI injection broken between POJOs

Problem

How can I inject an EJB into a domain object (an JPA entity) with Java EE 6?

Original source