Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/EclipseLink-ORM.XML"

Line 1: Line 1:
 
[[Category:EclipseLink/Example/JPA|EclipseLink-ORM.XML]]
 
[[Category:EclipseLink/Example/JPA|EclipseLink-ORM.XML]]
  
EclipseLink supports and extended JPA orm.xml format. This mapping file can be used in place of JPA's standard mapping file or can be used to override a JPA mapping file. In additional to allowing all of the standard JPA mapping capabilities it also includes advanced mapping types and options.
+
EclipseLink supports an extended JPA orm.xml mapping configuration file called '''eclipselink-orm.xml'''. This mapping file can be used in place of JPA's standard mapping file or can be used to override a JPA mapping file. In additional to allowing all of the standard JPA mapping capabilities it also includes advanced mapping types and options.
  
 
'''Note: Usage of this mapping file will enable many advanced features but may prevent the persistence unit from being portable to other JPA implementations'''
 
'''Note: Usage of this mapping file will enable many advanced features but may prevent the persistence unit from being portable to other JPA implementations'''
Line 7: Line 7:
 
== XML Configuration ==
 
== XML Configuration ==
  
The [http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_0.xsd EclipseLink ORM schema (eclipselink_orm_2_0.xsd)] can be used with the following header to define JPA and EclipseLink's advanced mappings.
+
The [http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_1.xsd EclipseLink ORM schema (eclipselink_orm_2_1.xsd)] can be used with the following header to define JPA and EclipseLink's advanced mappings.
  
 
<source lang="xml">
 
<source lang="xml">
Line 14: Line 14:
 
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
 
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_0.xsd"
+
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_1.xsd"
version="2.0">
+
version="2.1">
 
</entity-mappings>
 
</entity-mappings>
 
</source>
 
</source>
Line 26: Line 26:
 
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
 
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
+
version="2.1">
 
</entity-mappings>
 
</entity-mappings>
 
</source>
 
</source>
Line 40: Line 40:
 
</source>
 
</source>
  
== Complete Example ==
+
== Employee JPA Example using eclipselink-orm.xml ==
  
 
The [[EclipseLink/Examples/JPA/EmployeeXML | Employee JPA Example using XML]] illustrates how XML can be used exclusively (no annotations) to configure JPA usage. This example includes the usage of this EclipseLink specific JPA mapping XML file (see Employee example [http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.employee.xml/src/META-INF/eclipselink-orm.xml eclipselink-orm.xml]).
 
The [[EclipseLink/Examples/JPA/EmployeeXML | Employee JPA Example using XML]] illustrates how XML can be used exclusively (no annotations) to configure JPA usage. This example includes the usage of this EclipseLink specific JPA mapping XML file (see Employee example [http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.employee.xml/src/META-INF/eclipselink-orm.xml eclipselink-orm.xml]).
 +
 +
= EclipseLink ORM Features =
 +
 +
In addition to supporting all capabilities of JPA's orm.xml mapping file with similarly named elements and attributes the EclipseLink mapping file also offers many additional configuration capabilities.

Revision as of 12:25, 15 June 2010


EclipseLink supports an extended JPA orm.xml mapping configuration file called eclipselink-orm.xml. This mapping file can be used in place of JPA's standard mapping file or can be used to override a JPA mapping file. In additional to allowing all of the standard JPA mapping capabilities it also includes advanced mapping types and options.

Note: Usage of this mapping file will enable many advanced features but may prevent the persistence unit from being portable to other JPA implementations

XML Configuration

The EclipseLink ORM schema (eclipselink_orm_2_1.xsd) can be used with the following header to define JPA and EclipseLink's advanced mappings.

<?xml version="1.0"?>
<entity-mappings
	xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_1.xsd"
	version="2.1">
</entity-mappings>

EclipseLink automatically resolves the xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" to its internally packages schema. The following header will not cause the parser to attempt to access the XSD from the web. Using this however will require you to add the eclipselink_orm_2_0.xsd to your IDE's catalog in order to have XML completion available.

<?xml version="1.0"?>
<entity-mappings
	xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	version="2.1">
</entity-mappings>

Configuring usage in persistence.xml

A persistence unit can use one or more of these mapping files in the same way a standard JPA ORM mapping XML file can be used. The default location of /META-INF/orm.xml will automatically be picked up and used by any persistence unit.

If you want to use a different name for this mapping file or provide multiple mapping files they must be listed in the peristence.xml as:

<mapping-file>META-INF/additional-orm.xml</mapping-file>

Employee JPA Example using eclipselink-orm.xml

The Employee JPA Example using XML illustrates how XML can be used exclusively (no annotations) to configure JPA usage. This example includes the usage of this EclipseLink specific JPA mapping XML file (see Employee example eclipselink-orm.xml).

EclipseLink ORM Features

In addition to supporting all capabilities of JPA's orm.xml mapping file with similarly named elements and attributes the EclipseLink mapping file also offers many additional configuration capabilities.

Back to the top