EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration/JPA/orm.xml
|Mailing List • Forums • IRC|
Specifying Object-Relational Mappings Using orm.xml
Use the orm.xml file to apply the metadata to the persistence unit. This metadata is a union of all the mapping files and the annotations (if there is no xml-mapping-metadata-complete element). If you use one mapping orm.xml file for your metadata and place this file in a META-INF directory on the classpath, then you do not need to explicitly list it. The EclipseLink persistence provider will automatically search for this file (orm.xml) and use it.
The schema for the JPA 2.0 orm.xml is orm_2_0.xsd.
If you use a different name for your mapping files or place them in a different location, you must list them in the mapping-file element of the persistence.xml file, as shown here:
<persistence-unit name="EmployeeService"> <jta-data-source>jdbc/EmployeeServiceDS</jta-data-source> <mapping-file>META-INF/employee_service_queries.xml</mapping-file> </persistence-unit>
The following is an example of an orm.xml file.
<?xml version="1.0" encoding="UTF-8"?> <entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"> <description>The minimal mappings for a persistent entity in XML.</description> <entity name="Employee" class="org.acme.Employee" access="FIELD"> <attributes> <id name="id"/> </attributes> </entity> </entity-mappings>
Advantages and Disadvantages of Using XML
Some advantages of using XML instead of Annotations include:
- No coupling between the metadata and the source code
- Compliance with the existing, pre-EJB 3.0 development process
- Support in IDEs and source control systems
The main disadvantages of mapping with XML include:
- Its inherent complexitiy (when compared to annotations)
- The need for replication of the code context