2.1.6 Scope of support for the annotations included in the javax.persistence package

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:

Organization of this subsection
(1) Annotations that depend on the JPA Provider
(2) Annotations that do not depend on the JPA Provider

(1) Annotations that depend on the JPA Provider

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:

(a) WAR file (Servlet 3.0 compliant)

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 nameServlet specificationsJSP specificationsException classManagedBean (JSF)Other class
ServletServlet (API)Servlet filterServlet filter (API)Event listenerEvent listener (API)JSP FILETag handlerTag library event listener
Classic tag handlerSimple tag handler
@PersistenceContextY--Y--Y----YYN--Y--
@PersistenceContextsY--Y--Y----YYN--Y--
@PersistencePropertyY--Y--Y----YYN--Y--
@PersistenceUnitY--Y--Y----YYN--Y--
@PersistenceUnitsY--Y--Y----YYN--Y--
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not supported by standard specifications.

(b) WAR file (Supported by Servlet 2.5)

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 nameServlet specificationsJSP specificationsOther class
ServletServlet filterEvent listenerJSP fileTag handlerTag library event listener
Classic tag handlerSimple tag handler
@PersistenceContextYYY--YYN--
@PersistenceContextsYYY--YYN--
@PersistencePropertyYYY--YYN--
@PersistenceUnitYYY--YYN--
@PersistenceUnitsYYY--YYN--
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not applicable.

(c) EJB-JAR file (EJB3.1/EJB3.0 compliant)

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 nameEnterprise BeanException classOther class
InterfaceSession BeanEntity BeanMessage-driven BeanInterceptor
Other than default InterceptorDefault Interceptor
@PersistenceContext--Y--NYY----
@PersistenceContexts--Y--NYY----
@PersistenceProperty--Y--NYY----
@PersistenceUnit--Y--NYY----
@PersistenceUnits--Y--NYY----
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not applicable.

(d) Library JAR file (Servlets or JSPs)

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 nameServlet specificationsJSP specifications
ServletServlet (API)Servlet filterServlet filter (API)Event listenerEvent listener (API)JSP FILETag handlerTag library event listener
Classic tag handlerSimple tag handler
@PersistenceContext----Y--Y----YYN
@PersistenceContexts----Y--Y----YYN
@PersistenceProperty----Y--Y----YYN
@PersistenceUnit----Y--Y----YYN
@PersistenceUnits----Y--Y----YYN
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not applicable.

(e) Library JAR file (Enterprise Bean, exception class, or other classes)

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 nameEnterprise BeanException class
InterfaceSession BeanEntity BeanMessage-driven BeanInterceptor
@PersistenceContext------NY--
@PersistenceContexts------NY--
@PersistenceProperty------NY--
@PersistenceUnit------NY--
@PersistenceUnits------NY--
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not applicable.

(2) Annotations that do not depend on the JPA Provider

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.