Java Reference
In-Depth Information
JPA O/R mapping
Typically, JPA uses annotations for all of its O/R mappings. Sometimes annotations aren't
a sufficient solution. An example is if the details of your object model change in different
environments. In this case, JPA has orm.xml for specifying O/R mappings outside of code.
When packaging your EE application, orm.xml goes side by side with persistence.xml. It
can also be packaged with a location and name specified by <mapping-file> in per-
sistence.xml. As with all deployment descriptors, if it exits, its configuration takes preced-
ence over any annotations.
Because JPA is now its own specification, we won't go into any more detail here. We've
given the requirements of packaging JPA entities in an EE application and described the
basics of a persistence.xml file. Refer to the JPA specification or another Manning book for
more information on JPA.
13.5. CDI packaging
Similar to JPA, CDI doesn't define any special deployment module because dependency in-
jection isn't limited to a Java EE environment. CDI 1.1 for Java EE 7 is defined in JSR 346
( http://jcp.org/en/jsr/detail?id=346 ) , which extends JSR 299 and JSR 330. CDI 1.1 adds
specific requirements for dependency injection in a Java EE environment. But dependency
injection may also be used in a Java Standard application. Therefore, like JPA, CDI doesn't
have its own EE module but is simply included as a part of other modules. In this section
we'll quickly review how CDI is packaged as part of other EE modules, specifically JAR
archives, EJB-JAR modules, and WAR modules. Refer to chapter 12 for more details about
CDI.
13.5.1. CDI modules
When an EE application is deployed, CDI goes through bean discovery. Bean discovery is
a process of determining which artifacts inside the EE application use CDI. These artifacts
contain beans that the EE server must manage. An artifact may be a regular JAR archive or
any of the Enterprise module types (see table 13.1 ). Bean discovery is simply looking for
the beans.xml file in the following locations:
Search WWH ::




Custom Search