Tuesday, August 26, 2008

Describe the purposes and uses of annotations and deployment descriptors - SCBCD Exam Objective EJB3 JEE5

Describe the purposes and uses of annotations and deployment descriptors, including how the two mechanisms interact, how overriding is handled, and how these mechanisms function at the class, method, and field levels.


One of the things you've got to know about this objective is that deployment descriptors override annotations, so if there is a conflict between the two, the deployment descriptor wins. This makes it possible for developers to create components that work in a typical use, but can be customized for their particular environment at deployment time.

Also, annotations can be put on properties, or getters for the properties, but the two styles can't be mixed within the same class. At least, that was my experience with Hibernate - I can't think of why it would be any different in an EJB3.0 environment. I'll test it out, though.

Metadata Annotations and Deployment Descriptors

"One of the key enabling technologies introduced by J2SE 5.0 is the program annotation facility defined by JSR-175 [10]. This facility allows developers to annotate program elements in Java programming language source files to control the behavior and deployment of an application. Metadata annotations are a key element in the simplification of the development of EJB 3.0 applications. Metadata annotations are used by the developer to specify expected requirements on container behavior, to request the injection of services and resources, and to specify object/relational mappings. Metadata annotations may be used as an alternative to the deployment descriptors that were required by earlier versions of the Enterprise JavaBeans specification. While this document is written in terms of the usage of metadata annotations, it is not required that metadata annotations be used in an EJB 3.0 application. Developers who prefer the use of a deployment descriptor as an alternative to metadata annotations may define one for this purpose. The EJB 3.0 deployment descriptor is defined in the document “EJB Core Contracts and Requirements” [1] of this specification.

Deployment Descriptors

Deployment descriptors are defined by this specification as an alternative to metadata annotations or as a mechanism for the overriding of metadata annotations—for example to permit the further customization of an application for a particular development environment at a later stage of the development or assembly work flow. Deployment descriptors may be “sparse”, unlike the full deployment descriptors required by the EJB 2.1 specification. See “EJB Core Contracts and Requirements” [1]. Although it is not anticipated as a typical use case, it is possible for the application developer to combine the use of metadata annotations and deployment descriptors in the design of an application. When such a combination is used, the rules for the use of deployment descriptors as an overriding mechanism apply."

No comments: