The components in which the annotations of the javax.persistence package can be used differ based on the dependability on the JPA Provider. The annotations that depend on the JPA Provider and the annotations that do not depend on the JPA Provider are described separately:
This point describes the applicability of the annotations that depend on the JPA Provider. The annotations that can be coded in each component are as follows:
The following table lists the annotations that you can code in a WAR file:
Table 2-18 Annotations (javax. persistence package) that can be coded in WAR file (Servlet 3.0 compliant)
Annotation name | Servlet specifications | JSP specifications | Exception class | ManagedBean (JSF) | Other class | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Servlet | Servlet (API) | Servlet filter | Servlet filter (API) | Event listener | Event listener (API) | JSP FILE | Tag handler | Tag library event listener | |||||
Classic tag handler | Simple tag handler | ||||||||||||
@PersistenceContext | Y | -- | Y | -- | Y | -- | -- | Y | Y | N | -- | Y | -- |
@PersistenceContexts | Y | -- | Y | -- | Y | -- | -- | Y | Y | N | -- | Y | -- |
@PersistenceProperty | Y | -- | Y | -- | Y | -- | -- | Y | Y | N | -- | Y | -- |
@PersistenceUnit | Y | -- | Y | -- | Y | -- | -- | Y | Y | N | -- | Y | -- |
@PersistenceUnits | Y | -- | Y | -- | Y | -- | -- | Y | Y | N | -- | Y | -- |
The following table lists the annotations that you can code in a WAR file:
Table 2-19 Annotations (javax.persistence package) that can be coded in a WAR file (Supported by Servlet 2.5)
Annotation name | Servlet specifications | JSP specifications | Other class | |||||
---|---|---|---|---|---|---|---|---|
Servlet | Servlet filter | Event listener | JSP file | Tag handler | Tag library event listener | |||
Classic tag handler | Simple tag handler | |||||||
@PersistenceContext | Y | Y | Y | -- | Y | Y | N | -- |
@PersistenceContexts | Y | Y | Y | -- | Y | Y | N | -- |
@PersistenceProperty | Y | Y | Y | -- | Y | Y | N | -- |
@PersistenceUnit | Y | Y | Y | -- | Y | Y | N | -- |
@PersistenceUnits | Y | Y | Y | -- | Y | Y | N | -- |
The following table lists the annotations that you can code in an EJB-JAR file:
Table 2-20 Annotations (javax.persistence package) that can be coded in an EJB-JAR file (Supported by EJB3.0)
Annotation name | Enterprise Bean | Exception class | Other class | |||||
---|---|---|---|---|---|---|---|---|
Interface | Session Bean | Entity Bean | Message-driven Bean | Interceptor | ||||
Other than default Interceptor | Default Interceptor | |||||||
@PersistenceContext | -- | Y | -- | N | Y | Y | -- | -- |
@PersistenceContexts | -- | Y | -- | N | Y | Y | -- | -- |
@PersistenceProperty | -- | Y | -- | N | Y | Y | -- | -- |
@PersistenceUnit | -- | Y | -- | N | Y | Y | -- | -- |
@PersistenceUnits | -- | Y | -- | N | Y | Y | -- | -- |
The following table lists the annotations that you can code in a servlet or JSP of a library JAR file.
Table 2-21 Annotations (javax.persistence package) that can be coded in a library JAR file (Servlets or JSPs)
Annotation name | Servlet specifications | JSP specifications | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Servlet | Servlet (API) | Servlet filter | Servlet filter (API) | Event listener | Event listener (API) | JSP FILE | Tag handler | Tag library event listener | ||
Classic tag handler | Simple tag handler | |||||||||
@PersistenceContext | -- | -- | Y | -- | Y | -- | -- | Y | Y | N |
@PersistenceContexts | -- | -- | Y | -- | Y | -- | -- | Y | Y | N |
@PersistenceProperty | -- | -- | Y | -- | Y | -- | -- | Y | Y | N |
@PersistenceUnit | -- | -- | Y | -- | Y | -- | -- | Y | Y | N |
@PersistenceUnits | -- | -- | Y | -- | Y | -- | -- | Y | Y | N |
The following table lists the annotations that you can code in the Enterprise Beans, exception classes, or the other classes of a library JAR file:
Table 2-22 Annotations (javax.persistence package) that can be coded in a library JAR file (Enterprise Beans, exception classes, or other classes)
Annotation name | Enterprise Bean | Exception class | ||||
---|---|---|---|---|---|---|
Interface | Session Bean | Entity Bean | Message-driven Bean | Interceptor | ||
@PersistenceContext | -- | -- | -- | N | Y | -- |
@PersistenceContexts | -- | -- | -- | N | Y | -- |
@PersistenceProperty | -- | -- | -- | N | Y | -- |
@PersistenceUnit | -- | -- | -- | N | Y | -- |
@PersistenceUnits | -- | -- | -- | N | Y | -- |
Irrespective of the file type, you can use the annotations that do not depend on the JPA Provider, in the entity class.
For details on the list of annotations included in the javax.persistence package, see 2.7 javax.persistence package.