title: Specifying JPA entity listeners separately being independent of its associated entity
body: <p>Entity listeners are commonly placed over respective entity classes such as,</p>
  
  <pre><code>@Entity
  @EntityListeners(EntityListener.class)
  public class Entity implements Serializable {
  
      //...
  }
  </code></pre>
  
  <p>Applications may use one or more class libraries for sharing common functionalities across different projects/modules. In addition to the EE module, class libraries basically also require entities to be present on the compile-time class-path as a dependency i.e entities are present in both the places namely a class library and an EE module in an enterprise application. As such, the class <code>EntityListener</code> in the given example needs to be present on the compile-time class-path of a class library (it cannot only be added to the EE module).</p>
  
  <p>If entity listeners were not to be tightly-coupled with respective entities and be specified separately then, there would be no need to add this dependency (listeners) to a class library i.e. entity listeners would then be present only in the EE project where EJBs are perfectly eligible for injection using <code>@Inject</code>.</p>
  
  <p>Is there any possibility to separate this annotation <code>@EntityListeners(EntityListener.class)</code> from its associated entity so that it can be declared separately in a separate place? There should not be need to tightly couple this annotation with its respective entity.</p>
  
  <p>Using GlassFish 4.1 having EclipseLink 2.6.0 (JPA 2.1).</p>
  
  <hr>
  
  <p><sub>This is required as there is a <a href="https://stackoverflow.com/q/32600149/1391249">problem</a> injecting EJBs into such entity listeners <strong>available in class libraries</strong> using the CDI specific artifact <code>@Inject</code>. EJBs could otherwise be injected by using <code>@Inject</code> into listeners, if the listeners were present in the EE project (module) only (but not in a class library).
  </sub></p>