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 "Introduction to Projects (ELUG)"

m (New page: <div style="float:right;border:1px solid #000000;padding:5px">__TOC__ Related Topics</div> A EclipseLink project encapsulates both...)
 
m
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
[[Image:Elug draft icon.png]] '''For the latest EclipseLink documentation, please see http://www.eclipse.org/eclipselink/documentation/ '''
 +
 +
----
 +
 
<div style="float:right;border:1px solid #000000;padding:5px">__TOC__
 
<div style="float:right;border:1px solid #000000;padding:5px">__TOC__
 
[[Special:Whatlinkshere/Introduction to Projects (ELUG)|Related Topics]]</div>
 
[[Special:Whatlinkshere/Introduction to Projects (ELUG)|Related Topics]]</div>
A EclipseLink project encapsulates both mapping metadata and, where relevant, data source access information. The project is the primary object used by EclipseLink at run time. Each session (excluding the session broker) in a deployed application references a single project.
+
An EclipseLink project encapsulates both mapping metadata and, where relevant, data source access information. The project is the primary object used by EclipseLink at run time. Each session (excluding the session broker) in a deployed application references a single project.
  
  
  
 
==EclipseLink Project Types==
 
==EclipseLink Project Types==
This table lists the project types available in EclipseLink, classifies each as basic or advanced, and indicates how to create each.
+
This table lists the project types available in EclipseLink and indicates how to create each.
  
 
<span id="Table 13-1"></span>
 
<span id="Table 13-1"></span>
''''' EclipseLink Project Types'''''
 
 
{| class="RuleFormalWideMax" dir="ltr" title="EclipseLink Project Types" summary="This table describes each type of EclipseLink project and indicates whether it is a basic or advanced project." width="100%" border="1" frame="border" rules="all" cellpadding="3" frame="border" rules="all"
 
{| class="RuleFormalWideMax" dir="ltr" title="EclipseLink Project Types" summary="This table describes each type of EclipseLink project and indicates whether it is a basic or advanced project." width="100%" border="1" frame="border" rules="all" cellpadding="3" frame="border" rules="all"
 
|- align="left" valign="top"
 
|- align="left" valign="top"
Line 18: Line 21:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r2c1-t2" headers="r1c1-t2" align="left" |
 
| id="r2c1-t2" headers="r1c1-t2" align="left" |
Relational (see [[Introduction%20to%20Relational%20Projects%20(ELUG)|Introduction to Relational Projects]])
+
[[Introduction%20to%20Relational%20Projects%20(ELUG)|Relational Projects]]
 
| headers="r2c1-t2 r1c2-t2" align="left" |
 
| headers="r2c1-t2 r1c2-t2" align="left" |
 
A project for transactional persistence of Java objects to a relational database or an object-relational data type database accessed using Java Database Connectivity (JDBC). Supports EclipseLink queries and expressions.
 
A project for transactional persistence of Java objects to a relational database or an object-relational data type database accessed using Java Database Connectivity (JDBC). Supports EclipseLink queries and expressions.
Line 27: Line 30:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r3c1-t2" headers="r1c1-t2" align="left" |
 
| id="r3c1-t2" headers="r1c1-t2" align="left" |
EIS (see [[Introduction%20to%20EIS%20Projects%20(ELUG)|Introduction to EIS Projects]])
+
[[Introduction%20to%20EIS%20Projects%20(ELUG)|EIS Projects]]
 
| headers="r3c1-t2 r1c2-t2" align="left" |
 
| headers="r3c1-t2 r1c2-t2" align="left" |
 
A project for transactional persistence of Java objects to a nonrelational data source accessed using a Java EE Connector Architecture (JCA) adapter and any supported EIS record type, including indexed, mapped, or XML. Supports EclipseLink queries and expressions.
 
A project for transactional persistence of Java objects to a nonrelational data source accessed using a Java EE Connector Architecture (JCA) adapter and any supported EIS record type, including indexed, mapped, or XML. Supports EclipseLink queries and expressions.
Line 36: Line 39:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r4c1-t2" headers="r1c1-t2" align="left" |
 
| id="r4c1-t2" headers="r1c1-t2" align="left" |
XML (see [[Introduction%20to%20XML%20Projects%20(ELUG)|Introduction to XML Projects]])
+
[[Introduction%20to%20XML%20Projects%20(ELUG)|XML Projects]]
 
| headers="r4c1-t2 r1c2-t2" align="left" |
 
| headers="r4c1-t2 r1c2-t2" align="left" |
 
A project for nontransactional, nonpersistent (in-memory) conversion between Java objects and XML schema (XSD)-based documents using Java Architecture for XML Binding (JAXB). Does not support EclipseLink queries and expressions.
 
A project for nontransactional, nonpersistent (in-memory) conversion between Java objects and XML schema (XSD)-based documents using Java Architecture for XML Binding (JAXB). Does not support EclipseLink queries and expressions.
Line 44: Line 47:
 
[[Image:support.gif|Supported]]<br>
 
[[Image:support.gif|Supported]]<br>
 
|}
 
|}
 
<br>
 
  
 
For more information, see the following:
 
For more information, see the following:
Line 52: Line 53:
 
* [[Introduction%20to%20EclipseLink%20Sessions%20(ELUG)|Introduction to EclipseLink Sessions]]
 
* [[Introduction%20to%20EclipseLink%20Sessions%20(ELUG)|Introduction to EclipseLink Sessions]]
  
==Project Concepts==
 
This section describes concepts unique to EclipseLink projects, including the following:
 
* [[#Project Architecture]]
 
* [[#Relational and Nonrelational Projects]]
 
* [[#Persistent and Nonpersistent Projects]]
 
* [[#Projects and Login]]
 
* [[#Projects and Platforms]]
 
* [[#Projects and Sequencing]]
 
* [[#XML Namespaces]]
 
  
 +
 +
==Project Concepts==
 +
This section describes concepts unique to EclipseLink projects, including:
 +
* [[#Project Architecture|Project Architecture]]
 +
* [[#Relational and Nonrelational Projects|Relational and Nonrelational Projects]]
 +
* [[#Persistent and Nonpersistent Project|Persistent and Nonpersistent Projects]]
 +
* [[#Projects and Login|Projects and Login]]
 +
* [[#Projects and Platforms|Projects and Platforms]]
 +
* [[#Projects and Sequencing|Projects and Sequencing]]
 +
* [[#XML Namespaces|XML Namespaces]]
  
  
Line 69: Line 71:
 
This table summarizes the relationship between project, descriptor, and mappings.
 
This table summarizes the relationship between project, descriptor, and mappings.
  
 
+
<span id="Table 13-2"></span>
'''''Table 13-2 Project, Descriptor, and Mapping Support'''''
+
''''' Project, Descriptor, and Mapping Support'''''
  
 
{| class="RuleFormalMax" dir="ltr" title="Project, Descriptor, and Mapping Support" summary="This table summarizes the relationship between project, descriptor, and mappings." width="100%" border="1" frame="border" rules="all" cellpadding="3" frame="border" rules="all"
 
{| class="RuleFormalMax" dir="ltr" title="Project, Descriptor, and Mapping Support" summary="This table summarizes the relationship between project, descriptor, and mappings." width="100%" border="1" frame="border" rules="all" cellpadding="3" frame="border" rules="all"
Line 79: Line 81:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r2c1-t3" headers="r1c1-t3" align="left" |
 
| id="r2c1-t3" headers="r1c1-t3" align="left" |
[[Introduction%20to%20Relational%20Projects%20(ELUG)|Relational]]
+
[[Introduction%20to%20Relational%20Projects%20(ELUG)|Relational Projects]]
 
| headers="r2c1-t3 r1c2-t3" align="left" |
 
| headers="r2c1-t3 r1c2-t3" align="left" |
The following:
+
[[Introduction%20to%20Relational%20Descriptors%20(ELUG)|Relational Descriptors]] and [[Introduction%20to%20Object-Relational%20Data%20Type%20Descriptors%20(ELUG)|Object-Relational Data Type Descriptors]]
* Relational (see [[Introduction%20to%20Relational%20Descriptors%20(ELUG)|Relational Descriptors]])
+
* Object-relational data type (see [[Introduction%20to%20Object-Relational%20Data%20Type%20Descriptors%20(ELUG)|Object-Relational Data Type Descriptors]])
+
 
| headers="r2c1-t3 r1c3-t3" align="left" |
 
| headers="r2c1-t3 r1c3-t3" align="left" |
The following:
+
[[Introduction%20to%20Mappings%20(ELUG)#Relational Mappings|Relational Mappings]] and [[Introduction%20to%20Mappings%20(ELUG)#Object-Relational Data Type Mappings|Object-Relational Data Type Mappings]]
* Relational (see [[Introduction%20to%20Mappings%20(ELUG)|Relational Mappings]])
+
* Object-relational data type (see [[Introduction%20to%20Mappings%20(ELUG)|Object-Relational Data Type Mappings]])
+
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r3c1-t3" headers="r1c1-t3" align="left" |
 
| id="r3c1-t3" headers="r1c1-t3" align="left" |
EIS (see [[Introduction%20to%20EIS%20Projects%20(ELUG)|Introduction to EIS Projects]])
+
[[Introduction%20to%20EIS%20Projects%20(ELUG)|EIS Projects]]
 
| headers="r3c1-t3 r1c2-t3" align="left" |
 
| headers="r3c1-t3 r1c2-t3" align="left" |
EIS (see [[Introduction%20to%20EIS%20Descriptors%20(ELUG)|Descriptor Concepts]]
+
[[Introduction%20to%20EIS%20Descriptors%20(ELUG)|EIS Descriptor Concepts]]
 
| headers="r3c1-t3 r1c3-t3" align="left" |
 
| headers="r3c1-t3 r1c3-t3" align="left" |
EIS (see [[Introduction%20to%20Mappings%20(ELUG)|EIS Mappings]]
+
[[Introduction%20to%20Mappings%20(ELUG)#EIS Mappings|EIS Mappings]]
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r4c1-t3" headers="r1c1-t3" align="left" |
 
| id="r4c1-t3" headers="r1c1-t3" align="left" |
XML (see [[Introduction%20to%20XML%20Projects%20(ELUG)|Introduction to XML Projects]])
+
[[Introduction%20to%20XML%20Projects%20(ELUG)|XML Projects]]
 
| headers="r4c1-t3 r1c2-t3" align="left" |
 
| headers="r4c1-t3 r1c2-t3" align="left" |
XML (see [[Introduction%20to%20XML%20Descriptors%20(ELUG)|XML Descriptor Concepts]]
+
[[Introduction%20to%20XML%20Descriptors%20(ELUG)|XML Descriptor Concepts]]
 
| headers="r4c1-t3 r1c3-t3" align="left" |
 
| headers="r4c1-t3 r1c3-t3" align="left" |
XML (see [[Introduction%20to%20Mappings%20(ELUG)|ML Mappings]]
+
[[Introduction%20to%20Mappings%20(ELUG)#XML Mappings|XML Mappings]]
 
|}
 
|}
  
<br>
 
  
 
===Relational and Nonrelational Projects===
 
===Relational and Nonrelational Projects===
Line 111: Line 108:
 
Relational projects persist Java objects to a relational database.
 
Relational projects persist Java objects to a relational database.
  
Nonrelational projects persist Java objects to another (nonrelational) type of data source, or perform nonpersistent (see [[#Persistent and Nonpersistent Projects]]) data conversion. For example, to persist Java objects to an EIS data source by using a JCA adapter, use an EIS project. To perform nonpersistent (in-memory) conversions between Java objects and XML elements, use an XML project.
+
Nonrelational projects persist Java objects to another (nonrelational) type of data source, or perform nonpersistent (see [[#Persistent and Nonpersistent Projects|Persistent and Nonpersistent Projects]]) data conversion. For example, to persist Java objects to an EIS data source by using a JCA adapter, use an EIS project. To perform nonpersistent (in-memory) conversions between Java objects and XML elements, use an XML project.
 +
 
  
 
===Persistent and Nonpersistent Projects===
 
===Persistent and Nonpersistent Projects===
Line 117: Line 115:
  
 
EclipseLink also supports projects you use for applications that require only nonpersistent (in-memory) data conversion. For example, use an XML project to perform nonpersistent (in-memory) conversion between Java objects and XML elements.
 
EclipseLink also supports projects you use for applications that require only nonpersistent (in-memory) data conversion. For example, use an XML project to perform nonpersistent (in-memory) conversion between Java objects and XML elements.
 
  
  
Line 125: Line 122:
 
A login includes details of data source access, such as authentication, use of connection pools, and use of external transaction controllers. A login owns a platform.
 
A login includes details of data source access, such as authentication, use of connection pools, and use of external transaction controllers. A login owns a platform.
  
A platform includes options specific to a particular data source, such as binding, use of native SQL, use of batch writing, and sequencing. For more information about platforms, see [[#Projects and Platforms]].
+
A platform includes options specific to a particular data source, such as binding, use of native SQL, use of batch writing, and sequencing. For more information about platforms, see [[#Projects and Platforms|Projects and Platforms]].
  
 
For projects that do not persist to a data source, a login is not required. For projects that do persist to a data source, a login is always required.
 
For projects that do not persist to a data source, a login is not required. For projects that do persist to a data source, a login is always required.
Line 132: Line 129:
  
 
You can use a login in a variety of roles. A login's role determines where and how you create it. The login role you choose depends on the type of project you are creating and how you intend to use the login:
 
You can use a login in a variety of roles. A login's role determines where and how you create it. The login role you choose depends on the type of project you are creating and how you intend to use the login:
* [[#POJO Session Role]]
+
* [[#POJO Session Role|POJO Session Role]]
* [[#Development Role]]
+
* [[#Development Role|Development Role]]
 
+
  
  
Line 140: Line 136:
 
You create a session login in the <tt>sessions.xml</tt> file for EclipseLink applications that do not use container-managed persistence (CMP).
 
You create a session login in the <tt>sessions.xml</tt> file for EclipseLink applications that do not use container-managed persistence (CMP).
  
Typically, the EclipseLink runtime instantiates a project when you load a session from the <tt>sessions.xml</tt> file (see [[Acquiring%20and%20Using%20Sessions%20at%20Run%20Time%20(ELUG)|Acquiring and Using Sessions at Run Time]]). The runtime also instantiates a login and its platform based on the information in the <tt>sessions.xml</tt> file.
+
Typically, the EclipseLink runtime instantiates a project when you [[Acquiring%20and%20Using%20Sessions%20at%20Run%20Time%20(ELUG)#Acquiring and Using Sessions at Run Time|load a session from the <tt>sessions.xml</tt> file]]. The runtime also instantiates a login and its platform based on the information in the <tt>sessions.xml</tt> file.
  
 
The EclipseLink runtime uses the information in the session login whenever you perform a persistence operation using the session in your POJO EclipseLink application.
 
The EclipseLink runtime uses the information in the session login whenever you perform a persistence operation using the session in your POJO EclipseLink application.
  
If you are using Workbench and your login is based on a relational database platform, you must also configure a development login (see [[#Development Role]]).
+
If you are using Workbench and your login is based on a relational database platform, you must also configure [[#Development Role|a development login]].
  
 
If a <tt>sessions.xml</tt> file contains a login, this login overrides any other login definition.
 
If a <tt>sessions.xml</tt> file contains a login, this login overrides any other login definition.
  
There is a session login type for each project type that persists to a data source. For a complete list of login types available, see [[Introduction%20to%20Data%20Access%20(ELUG)|Data Source Login Types]].
+
There is a session login type for each project type that persists to a data source. For a complete list of login types available, see [[Introduction%20to%20Data%20Access%20(ELUG)#Data Source Login Types|Data Source Login Types]].
 
+
For information on configuring a session login, see [[Configuring%20a%20Session%20(ELUG)|Configuring a Session Login]].
+
  
 +
For information on configuring a session login, see [[Configuring%20a%20Session%20(ELUG)#Configuring a Session Login|Configuring a Session Login]].
  
  
Line 159: Line 154:
 
Workbench uses the information in the development login whenever you perform a data source operation from within Workbench, for example, whenever you read or write schema information from or to a data store during application development. The development login information is never written to a <tt>sessions.xml</tt> or <tt>project.xml</tt> file.
 
Workbench uses the information in the development login whenever you perform a data source operation from within Workbench, for example, whenever you read or write schema information from or to a data store during application development. The development login information is never written to a <tt>sessions.xml</tt> or <tt>project.xml</tt> file.
  
The development login is never used when you deploy your application: it is overridden by either the <tt>sessions.xml</tt> file (see [[#POJO Session Role]]) or the <tt>project.xml</tt> file.
+
The development login is never used when you deploy your application: it is overridden by either the <tt>sessions.xml</tt> file (see [[#POJO Session Role|POJO Session Role]]) or the <tt>project.xml</tt> file.
 +
 
 +
For more information on creating a development login, see [[Configuring%20a%20Relational%20Project%20(ELUG)#Configuring Development and Deployment Logins|Configuring Development and Deployment Logins]].
  
For more information on creating a development login, see [[Configuring%20a%20Relational%20Project%20(ELUG)|Configuring Development and Deployment Logins]].
 
  
 
===Projects and Platforms===
 
===Projects and Platforms===
Line 168: Line 164:
 
A platform includes options specific to a particular data source, such as binding, use of native SQL, use of batch writing, and sequencing.
 
A platform includes options specific to a particular data source, such as binding, use of native SQL, use of batch writing, and sequencing.
  
A login includes details of data source access, such as authentication, use of connection pools, and use of external transaction controllers. A login owns a platform. For more information about logins, see [[#Projects and Login]].
+
A login includes details of data source access, such as authentication, use of connection pools, and use of external transaction controllers. A login owns a platform. For more information about logins, see [[#Projects and Login|Projects and Login]].
  
 
For projects that do not persist to a data source, a platform is not required. For projects that do persist to a data source, a platform is always required.
 
For projects that do not persist to a data source, a platform is not required. For projects that do persist to a data source, a platform is always required.
Line 174: Line 170:
 
In Workbench, the project type determines the type of platform that the project uses, if applicable.
 
In Workbench, the project type determines the type of platform that the project uses, if applicable.
  
There is a platform type for each project type that persists to a data source. For a complete list of platform types available, see [[Introduction%20to%20Data%20Access%20(ELUG)|Data Source Platform Types]].
+
There is a platform type for each project type that persists to a data source. For a complete list of platform types available, see [[Introduction%20to%20Data%20Access%20(ELUG)#Data Source Platform Types|Data Source Platform Types]].
 +
 
  
 
===Projects and Sequencing===
 
===Projects and Sequencing===
An essential part of maintaining object identity (see [[Introduction%20to%20Cache%20(ELUG)|Cache Type and Object Identity]]) is sequencing: managing the assignment of unique values to distinguish one instance from another.
+
An essential part of [[Introduction%20to%20Cache%20(ELUG)#Cache Type and Object Identity|maintaining object identity]] is sequencing: managing the assignment of unique values to distinguish one instance from another.
  
 
Projects have different sequencing requirements, depending on their types:
 
Projects have different sequencing requirements, depending on their types:
  
 
* For relational projects, you typically obtain object identifier values from a separate sequence table (or database object) dedicated to managing object identifier values (see [[Introduction%20to%20Relational%20Projects%20(ELUG)|Sequencing in Relational Projects]]).
 
* For relational projects, you typically obtain object identifier values from a separate sequence table (or database object) dedicated to managing object identifier values (see [[Introduction%20to%20Relational%20Projects%20(ELUG)|Sequencing in Relational Projects]]).
* For EIS projects, you typically use a returning policy (see [[Configuring%20a%20Descriptor%20(ELUG)|Configuring Returning Policy]]) to obtain object identifier values managed by the EIS data source.
+
* For EIS projects, you typically [[Configuring%20a%20Descriptor%20(ELUG)#Configuring Returning Policy|use a returning policy]] to obtain object identifier values managed by the EIS data source.
 
* For XML projects, because you are simply performing transformations between objects and XML documents, sequencing is not an issue.
 
* For XML projects, because you are simply performing transformations between objects and XML documents, sequencing is not an issue.
  
To configure sequencing, you must configure:
+
To configure sequencing, you must configure the following:
* How to obtain sequence values (see [[#Configuring How to Obtain Sequence Values]]), and
+
* [[#Configuring How to Obtain Sequence Values|how to obtain sequence values]], and
* Where to write sequence values when an instance of a descriptor's reference class is created (see [[#Configuring Where to Write Sequence Values]])
+
* [[#Configuring Where to Write Sequence Values|where to write sequence values]] when an instance of a descriptor's reference class is created.
 
+
Depending on the type of sequencing you use and the architecture of your application, you may consider using a sequence connection pool. For more information, see [[Introduction%20to%20Data%20Access%20(ELUG)|Sequence Connection Pools]].
+
  
 +
Depending on the type of sequencing you use and the architecture of your application, you may consider using [[Introduction%20to%20Data%20Access%20(ELUG)#Sequence Connection Pools|Sequence Connection Pools]].
  
  
 
====Configuring How to Obtain Sequence Values====
 
====Configuring How to Obtain Sequence Values====
 
To determine how EclipseLink obtains sequence values, you configure EclipseLink sequencing at the project or session level, depending on the type of project you are building, as follows:
 
To determine how EclipseLink obtains sequence values, you configure EclipseLink sequencing at the project or session level, depending on the type of project you are building, as follows:
* In a POJO project, you can configure a session directly: in this case, you can use session-level sequence configuration instead of project-level sequence configuration or to override project level sequence configuration on a session-by-session basis, if required (see [[Configuring%20a%20Database%20Login%20(ELUG)|Configuring Sequencing at the Session Level]]).
+
* In a POJO project, you can configure a session directly: in this case, you can use session-level sequence configuration instead of project-level sequence configuration or to override project level sequence configuration on a session-by-session basis, if required (see [[Configuring%20a%20Database%20Login%20(ELUG)#Configuring Sequencing at the Session Level|Configuring Sequencing at the Session Level]]).
 +
 
  
 
====Configuring Where to Write Sequence Values====
 
====Configuring Where to Write Sequence Values====
To tell EclipseLink into which table and column to write the sequence value when an instance of a descriptor's reference class is created, you configure EclipseLink sequencing at the descriptor level (see [[Configuring%20a%20Relational%20Descriptor%20(ELUG)|Configuring Sequencing at the Descriptor Level]]).
+
To tell EclipseLink into which table and column to write the sequence value when an instance of a descriptor's reference class is created, you configure EclipseLink [[Configuring%20a%20Relational%20Descriptor%20(ELUG)#Configuring Sequencing at the Descriptor Level|sequencing at the descriptor level]].
 +
 
  
 
===XML Namespaces===
 
===XML Namespaces===
 
As defined in http://www.w3.org/TR/REC-xml-names/, an XML namespace is a collection of names, identified by a URI reference, which are used in XML documents as element types and attribute names. To promote reusability and modularity, XML document constructs should have universal names, whose scope extends beyond their containing document. XML namespaces are the mechanism which accomplishes this.
 
As defined in http://www.w3.org/TR/REC-xml-names/, an XML namespace is a collection of names, identified by a URI reference, which are used in XML documents as element types and attribute names. To promote reusability and modularity, XML document constructs should have universal names, whose scope extends beyond their containing document. XML namespaces are the mechanism which accomplishes this.
  
XML namespaces are applicable in projects that reference an XML schema: EIS projects that use XML records (see [[Creating%20an%20EIS%20Project%20(ELUG)|Creating an EIS Project with XML Records]]) and XML projects (see [[Introduction%20to%20XML%20Projects%20(ELUG)|XML Project Concepts]]).
+
XML namespaces are applicable in projects that reference an XML schema: [[Creating%20an%20EIS%20Project%20(ELUG)#Creating an EIS Project with XML Records|EIS projects that use XML records]] and [[Introduction%20to%20XML%20Projects%20(ELUG)#XML Project Concepts|XML projects]].
 +
 
 +
For more information, see [[#XML Namespaces Overview|XML Namespaces Overview]]].
 +
 
  
For more information, see [[#XML Namespaces Overview]].
 
  
 
==Project API==
 
==Project API==
 
This section describes the following:
 
This section describes the following:
 
* [[#Project Inheritance Hierarchy|Project Inheritance Hierarchy]]
 
* [[#Project Inheritance Hierarchy|Project Inheritance Hierarchy]]
 
  
  
 
===Project Inheritance Hierarchy===
 
===Project Inheritance Hierarchy===
 
There is only one type of project: <tt>org.eclipse.eclipselink.sessions.Project</tt>.
 
There is only one type of project: <tt>org.eclipse.eclipselink.sessions.Project</tt>.
 +
 +
  
 
==XML Namespaces Overview==
 
==XML Namespaces Overview==
 
As defined in http://www.w3.org/TR/REC-xml-names/, an XML namespace is a collection of names, identified by a URI reference, which are used in XML documents as element types and attribute names. To promote reusability and modularity, XML document constructs should have universal names, whose scope extends beyond their containing document. XML namespaces are the mechanism which accomplishes this.
 
As defined in http://www.w3.org/TR/REC-xml-names/, an XML namespace is a collection of names, identified by a URI reference, which are used in XML documents as element types and attribute names. To promote reusability and modularity, XML document constructs should have universal names, whose scope extends beyond their containing document. XML namespaces are the mechanism which accomplishes this.
  
XML namespaces are applicable in projects that reference an XML schema: EIS projects that use XML records (see [[Creating%20an%20EIS%20Project%20(ELUG)|Creating an EIS Project with XML Records]]) and XML projects (see [[Introduction%20to%20XML%20Projects%20(ELUG)|XML Project Concepts]]).
+
XML namespaces are applicable in projects that reference an XML schema: [[Creating%20an%20EIS%20Project%20(ELUG)#Creating an EIS Project with XML Records|EIS projects that use XML records]] and [[Introduction%20to%20XML%20Projects%20(ELUG)#XML Project Concepts|XML projects]].
  
 
This section describes the following:
 
This section describes the following:
* [[#Workbench Namespace Resolution]]
+
* [[#Workbench Namespace Resolution|Workbench Namespace Resolution]]
* [[#Element and Attribute Form Options]]
+
* [[#Element and Attribute Form Options|Element and Attribute Form Options]]
* [[#EclipseLink Runtime Namespace Resolution]]
+
* [[#EclipseLink Runtime Namespace Resolution|EclipseLink Runtime Namespace Resolution]]
 
+
  
  
 
===Workbench Namespace Resolution===
 
===Workbench Namespace Resolution===
Using Workbench, you can configure the XML schema namespace for your project. For more information, see [[Using%20Workbench%20(ELUG)|How to Configure XML Schema Namespace]].
+
Using Workbench, you can configure the XML schema namespace for your project. For more information, see [[Using%20Workbench%20(ELUG)#How to Configure XML Schema Namespace|How to Configure XML Schema Namespace]].
 
+
  
  
Line 237: Line 236:
  
 
This section describes the consequences of the following combinations of element and attribute form configuration:
 
This section describes the consequences of the following combinations of element and attribute form configuration:
* [[#Element Form Default Qualified and Attribute Form Default Unqualified]]
+
* [[#Element Form Default Qualified and Attribute Form Default Unqualified|Element Form Default Qualified and Attribute Form Default Unqualified]]
* [[#Element and Attribute Form Default Unqualified]]
+
* [[#Element and Attribute Form Default Unqualified|Element and Attribute Form Default Unqualified]]
* [[#Element and Attribute Form Default Qualified]]
+
* [[#Element and Attribute Form Default Qualified|Element and Attribute Form Default Qualified]]
 
+
  
  
 
====Element Form Default Qualified and Attribute Form Default Unqualified====
 
====Element Form Default Qualified and Attribute Form Default Unqualified====
[[#Example 13-1|XML Schema with Element Form Default Qualified and Attribute Form Default Unqualified]] shows an XML schema in which a target namespace is set. It is coded with <tt>elementFormDefault</tt> set to <tt>qualified</tt> and <tt>attributeFormDefault</tt> set to <tt>unqualified</tt>. This means all elements must be namespace qualified and globally declared attributes must be namespace qualified and locally defined attributes must not be namespace qualified.
+
The [[#Example 13-1|XML Schema with Element Form Default Qualified and Attribute Form Default Unqualified]] example shows an XML schema in which a target namespace is set. It is coded with <tt>elementFormDefault</tt> set to <tt>qualified</tt> and <tt>attributeFormDefault</tt> set to <tt>unqualified</tt>. This means all elements must be namespace qualified and globally declared attributes must be namespace qualified and locally defined attributes must not be namespace qualified.
  
  
 
<span id="Example 13-1"></span>
 
<span id="Example 13-1"></span>
 
''''' XML Schema with Element Form Default Qualified and Attribute Form Default Unqualified'''''
 
''''' XML Schema with Element Form Default Qualified and Attribute Form Default Unqualified'''''
 
+
<source lang="xml">
+
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
 
  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
Line 269: Line 266:
 
     <xsd:element name="date-of-birth" type="xsd:date"/>
 
     <xsd:element name="date-of-birth" type="xsd:date"/>
 
  </xsd:schema>
 
  </xsd:schema>
 
+
</source>
 
+
  
 
This example shows an XML document that conforms to this XML schema.
 
This example shows an XML document that conforms to this XML schema.
 
  
 
<span id="Example 13-2"></span>
 
<span id="Example 13-2"></span>
 
''''' XML Document'''''
 
''''' XML Document'''''
 +
<source lang="xml">
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" id="1">
 
  <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" id="1">
Line 283: Line 279:
 
   
 
   
 
  </'''<tt>ns:</tt>'''customer>
 
  </'''<tt>ns:</tt>'''customer>
 +
</source>
  
 
+
The [[#Example 13-3|XML Descriptors and Mappings]] example shows the Java code for a <tt>Customer</tt> class <tt>XMLDescriptor</tt> and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see [[Configuring%20an%20XML%20Descriptor%20(ELUG)#Configuring an XML Descriptor|Configuring an XML Descriptor]] and [[Configuring%20an%20XML%20Mapping%20(ELUG)#Configuring an XML Mapping|Configuring an XML Mapping]]).
 
+
[[#Example 13-3|'XML Descriptors and Mappings]] shows the Java code for a <tt>Customer</tt> class <tt>XMLDescriptor</tt> and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see [[Configuring%20an%20XML%20Descriptor%20(ELUG)|Configuring an XML Descriptor]] and [[Configuring%20an%20XML%20Mapping%20(ELUG)|Configuring an XML Mapping]]).
+
  
  
 
<span id="Example 13-3"></span>
 
<span id="Example 13-3"></span>
 
'''''XML Descriptors and Mappings'''''
 
'''''XML Descriptors and Mappings'''''
 +
<source lang="java">
 
  NamespaceResolver namespaceResolver = new NamespaceResolver();
 
  NamespaceResolver namespaceResolver = new NamespaceResolver();
 
  namespaceResolver.put("ns", "urn:namespace-example");
 
  namespaceResolver.put("ns", "urn:namespace-example");
Line 312: Line 308:
 
  birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 
  birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 
  customerDescriptor.addMapping(birthDateMapping);
 
  customerDescriptor.addMapping(birthDateMapping);
 
+
</source>
 
+
  
 
====Element and Attribute Form Default Unqualified====
 
====Element and Attribute Form Default Unqualified====
[[#Example 13-4|XML Schema with Element and Attribute Form Default Unqualified]] shows an XML schema in which a target namespace is set. It is coded with <tt>elementFormDefault</tt> and <tt>attributeFormDefault</tt> set to <tt>unqualified</tt>. This means that globally defined nodes must be namespace qualified and locally defined nodes must not be namespace qualified.
+
The [[#Example 13-4|XML Schema with Element and Attribute Form Default Unqualified]] example shows an XML schema in which a target namespace is set. It is coded with <tt>elementFormDefault</tt> and <tt>attributeFormDefault</tt> set to <tt>unqualified</tt>. This means that globally defined nodes must be namespace qualified and locally defined nodes must not be namespace qualified.
  
  
 
<span id="Example 13-4"></span>
 
<span id="Example 13-4"></span>
 
''''' XML Schema with Element and Attribute Form Default Unqualified'''''
 
''''' XML Schema with Element and Attribute Form Default Unqualified'''''
 +
<source lang="xml">
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
   
 
   
Line 340: Line 336:
 
   
 
   
 
  </xsd:schema>
 
  </xsd:schema>
 
+
</source>
 
+
  
 
This example shows an XML document that conforms to this XML schema.
 
This example shows an XML document that conforms to this XML schema.
 
  
 
<span id="Example 13-5"></span>
 
<span id="Example 13-5"></span>
 
''''' XML Document'''''
 
''''' XML Document'''''
 +
<source lang="xml">
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" id="1">
 
  <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" id="1">
Line 355: Line 350:
 
  </'''<tt>ns:</tt>'''customer>
 
  </'''<tt>ns:</tt>'''customer>
 
   
 
   
 +
</source>
  
 
+
The [[#Example 13-6|XML Descriptors and Mappings]] example shows the Java code for a <tt>Customer</tt> class <tt>XMLDescriptor</tt> and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see [[Configuring%20an%20XML%20Descriptor%20(ELUG)|Configuring an XML Descriptor]] and [[Configuring%20an%20XML%20Mapping%20(ELUG)|Configuring an XML Mapping]]).
 
+
[[#Example 13-6|XML Descriptors and Mappings]] shows the Java code for a <tt>Customer</tt> class <tt>XMLDescriptor</tt> and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see [[Configuring%20an%20XML%20Descriptor%20(ELUG)|Configuring an XML Descriptor]] and [[Configuring%20an%20XML%20Mapping%20(ELUG)|Configuring an XML Mapping]]).
+
  
  
 
<span id="'Example 13-6"></span>
 
<span id="'Example 13-6"></span>
'''' XML Descriptors and Mappings'''''
+
'''''XML Descriptors and Mappings'''''
+
<source lang="java">
 
  NamespaceResolver namespaceResolver = new NamespaceResolver();
 
  NamespaceResolver namespaceResolver = new NamespaceResolver();
 
  namespaceResolver.put("ns", "urn:namespace-example");
 
  namespaceResolver.put("ns", "urn:namespace-example");
Line 385: Line 379:
 
  birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 
  birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 
  customerDescriptor.addMapping(birthDateMapping);
 
  customerDescriptor.addMapping(birthDateMapping);
 
+
</source>
  
  
 
====Element and Attribute Form Default Qualified====
 
====Element and Attribute Form Default Qualified====
[[#Example 13-7|XML Schema with Element and Attribute Form Default Qualified']] shows an XML schema in which a target namespace is set. It is coded with <tt>elementFormDefault</tt> and <tt>attributeFormDefault</tt> set to qualified. This means that all nodes must be namespace qualified.
+
The [[#Example 13-7|XML Schema with Element and Attribute Form Default Qualified]] example shows an XML schema in which a target namespace is set. It is coded with <tt>elementFormDefault</tt> and <tt>attributeFormDefault</tt> set to qualified. This means that all nodes must be namespace qualified.
  
  
 
<span id="Example 13-7"></span>
 
<span id="Example 13-7"></span>
 
'''''XML Schema with Element and Attribute Form Default Qualified'''''
 
'''''XML Schema with Element and Attribute Form Default Qualified'''''
 +
<source lang="xml">
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
 
  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
Line 412: Line 407:
 
     <xsd:element name="date-of-birth" type="xsd:date"/>
 
     <xsd:element name="date-of-birth" type="xsd:date"/>
 
  </xsd:schema>
 
  </xsd:schema>
 
+
</source>
 
+
  
 
This example shows an XML document that conforms to this XML schema.
 
This example shows an XML document that conforms to this XML schema.
Line 419: Line 413:
 
<span id="Example 13-8"></span>
 
<span id="Example 13-8"></span>
 
''''' XML Document'''''
 
''''' XML Document'''''
 +
<source lang="xml">
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" '''<tt>ns:</tt>'''id="1">
 
  <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" '''<tt>ns:</tt>'''id="1">
Line 425: Line 420:
 
   
 
   
 
  </'''<tt>ns:</tt>'''customer>
 
  </'''<tt>ns:</tt>'''customer>
 +
</source>
  
 
+
The [[#Example 13-9|XML Descriptors and Mappings]] exampel shows the Java code for a <tt>Customer</tt> class <tt>XMLDescriptor</tt> and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see [[Configuring%20an%20XML%20Descriptor%20(ELUG)#Configuring an XML Descriptor|Configuring an XML Descriptor]] and [[Configuring%20an%20XML%20Mapping%20(ELUG)#Configuring an XML Mapping|Configuring an XML Mapping]]).
[[#Example 13-9|XML Descriptors and Mappings]] shows the Java code for a <tt>Customer</tt> class <tt>XMLDescriptor</tt> and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see [[Configuring%20an%20XML%20Descriptor%20(ELUG)|Configuring an XML Descriptor]] and [[Configuring%20an%20XML%20Mapping%20(ELUG)|Configuring an XML Mapping]]).
+
  
  
 
<span id="Example 13-9"></span>
 
<span id="Example 13-9"></span>
 
''''' XML Descriptors and Mappings'''''
 
''''' XML Descriptors and Mappings'''''
 
+
<source lang="java">
 
  NamespaceResolver namespaceResolver = new NamespaceResolver();
 
  NamespaceResolver namespaceResolver = new NamespaceResolver();
 
  namespaceResolver.put("ns", "urn:namespace-example");
 
  namespaceResolver.put("ns", "urn:namespace-example");
Line 454: Line 449:
 
  birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 
  birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 
  customerDescriptor.addMapping(birthDateMapping);
 
  customerDescriptor.addMapping(birthDateMapping);
 +
</source>
  
 
===EclipseLink Runtime Namespace Resolution===
 
===EclipseLink Runtime Namespace Resolution===
 
It is common for an XML document to include one or more namespaces. EclipseLink supports this using its <tt>NamespaceResolver</tt>. The namespace resolver maintains pairs of namespace prefixes and Uniform Resource Identifiers (URIs). EclipseLink uses these prefixes in conjunction with the XPath statements you specify on EIS mappings to XML records and XML mappings.
 
It is common for an XML document to include one or more namespaces. EclipseLink supports this using its <tt>NamespaceResolver</tt>. The namespace resolver maintains pairs of namespace prefixes and Uniform Resource Identifiers (URIs). EclipseLink uses these prefixes in conjunction with the XPath statements you specify on EIS mappings to XML records and XML mappings.
  
Although EclipseLink captures namespace prefixes in the XPath statements for mappings (if applicable), the input document is not required to use the same namespace prefixes. As [[#Example 13-9|XML Descriptors and Mappings]] shows, EclipseLink will use the namespace prefixes specified in the mapping when creating new documents.
+
Although EclipseLink captures namespace prefixes in the XPath statements for mappings (if applicable), the input document is not required to use the same namespace prefixes. As the [[#Example 13-9|XML Descriptors and Mappings]] example shows, EclipseLink will use the namespace prefixes specified in the mapping when creating new documents.
  
  
Line 473: Line 469:
  
 
[[Category: EclipseLink User's Guide]]
 
[[Category: EclipseLink User's Guide]]
[[Category: Draft]]
+
[[Category: Release 1]]
 
[[Category: Concept]]
 
[[Category: Concept]]

Latest revision as of 11:23, 18 July 2012

Elug draft icon.png For the latest EclipseLink documentation, please see http://www.eclipse.org/eclipselink/documentation/


An EclipseLink project encapsulates both mapping metadata and, where relevant, data source access information. The project is the primary object used by EclipseLink at run time. Each session (excluding the session broker) in a deployed application references a single project.


EclipseLink Project Types

This table lists the project types available in EclipseLink and indicates how to create each.

Project Type Description EclipseLink Workbench Java

Relational Projects

A project for transactional persistence of Java objects to a relational database or an object-relational data type database accessed using Java Database Connectivity (JDBC). Supports EclipseLink queries and expressions.

Supported

Supported

EIS Projects

A project for transactional persistence of Java objects to a nonrelational data source accessed using a Java EE Connector Architecture (JCA) adapter and any supported EIS record type, including indexed, mapped, or XML. Supports EclipseLink queries and expressions.

Supported

Supported

XML Projects

A project for nontransactional, nonpersistent (in-memory) conversion between Java objects and XML schema (XSD)-based documents using Java Architecture for XML Binding (JAXB). Does not support EclipseLink queries and expressions.

Supported

Supported

For more information, see the following:


Project Concepts

This section describes concepts unique to EclipseLink projects, including:


Project Architecture

The project type you choose determines the type of descriptors and mappings you can use. There is a project type for each data source type that EclipseLink supports.

This table summarizes the relationship between project, descriptor, and mappings.

Project, Descriptor, and Mapping Support

Project Descriptor Mapping

Relational Projects

Relational Descriptors and Object-Relational Data Type Descriptors

Relational Mappings and Object-Relational Data Type Mappings

EIS Projects

EIS Descriptor Concepts

EIS Mappings

XML Projects

XML Descriptor Concepts

XML Mappings


Relational and Nonrelational Projects

EclipseLink supports both relational and nonrelational projects.

Relational projects persist Java objects to a relational database.

Nonrelational projects persist Java objects to another (nonrelational) type of data source, or perform nonpersistent (see Persistent and Nonpersistent Projects) data conversion. For example, to persist Java objects to an EIS data source by using a JCA adapter, use an EIS project. To perform nonpersistent (in-memory) conversions between Java objects and XML elements, use an XML project.


Persistent and Nonpersistent Projects

EclipseLink supports projects you use for applications that require persistent storage of Java objects. For example, use a relational project to persist Java objects to a relational database, or an EIS project to persist Java objects to an EIS data source by way of a JCA adapter.

EclipseLink also supports projects you use for applications that require only nonpersistent (in-memory) data conversion. For example, use an XML project to perform nonpersistent (in-memory) conversion between Java objects and XML elements.


Projects and Login

The login (if any) associated with a project determines how the EclipseLink runtime connects to the project's data source.

A login includes details of data source access, such as authentication, use of connection pools, and use of external transaction controllers. A login owns a platform.

A platform includes options specific to a particular data source, such as binding, use of native SQL, use of batch writing, and sequencing. For more information about platforms, see Projects and Platforms.

For projects that do not persist to a data source, a login is not required. For projects that do persist to a data source, a login is always required.

In Workbench, the project type determines the type of login that the project uses, if applicable.

You can use a login in a variety of roles. A login's role determines where and how you create it. The login role you choose depends on the type of project you are creating and how you intend to use the login:


POJO Session Role

You create a session login in the sessions.xml file for EclipseLink applications that do not use container-managed persistence (CMP).

Typically, the EclipseLink runtime instantiates a project when you load a session from the sessions.xml file. The runtime also instantiates a login and its platform based on the information in the sessions.xml file.

The EclipseLink runtime uses the information in the session login whenever you perform a persistence operation using the session in your POJO EclipseLink application.

If you are using Workbench and your login is based on a relational database platform, you must also configure a development login.

If a sessions.xml file contains a login, this login overrides any other login definition.

There is a session login type for each project type that persists to a data source. For a complete list of login types available, see Data Source Login Types.

For information on configuring a session login, see Configuring a Session Login.


Development Role

Using Workbench, you create a development login in the Workbench project file when your project is based on a relational database platform.

Workbench uses the information in the development login whenever you perform a data source operation from within Workbench, for example, whenever you read or write schema information from or to a data store during application development. The development login information is never written to a sessions.xml or project.xml file.

The development login is never used when you deploy your application: it is overridden by either the sessions.xml file (see POJO Session Role) or the project.xml file.

For more information on creating a development login, see Configuring Development and Deployment Logins.


Projects and Platforms

The platform (if any) associated with a project tells the EclipseLink runtime what specific type of data source a project uses.

A platform includes options specific to a particular data source, such as binding, use of native SQL, use of batch writing, and sequencing.

A login includes details of data source access, such as authentication, use of connection pools, and use of external transaction controllers. A login owns a platform. For more information about logins, see Projects and Login.

For projects that do not persist to a data source, a platform is not required. For projects that do persist to a data source, a platform is always required.

In Workbench, the project type determines the type of platform that the project uses, if applicable.

There is a platform type for each project type that persists to a data source. For a complete list of platform types available, see Data Source Platform Types.


Projects and Sequencing

An essential part of maintaining object identity is sequencing: managing the assignment of unique values to distinguish one instance from another.

Projects have different sequencing requirements, depending on their types:

  • For relational projects, you typically obtain object identifier values from a separate sequence table (or database object) dedicated to managing object identifier values (see Sequencing in Relational Projects).
  • For EIS projects, you typically use a returning policy to obtain object identifier values managed by the EIS data source.
  • For XML projects, because you are simply performing transformations between objects and XML documents, sequencing is not an issue.

To configure sequencing, you must configure the following:

Depending on the type of sequencing you use and the architecture of your application, you may consider using Sequence Connection Pools.


Configuring How to Obtain Sequence Values

To determine how EclipseLink obtains sequence values, you configure EclipseLink sequencing at the project or session level, depending on the type of project you are building, as follows:

  • In a POJO project, you can configure a session directly: in this case, you can use session-level sequence configuration instead of project-level sequence configuration or to override project level sequence configuration on a session-by-session basis, if required (see Configuring Sequencing at the Session Level).


Configuring Where to Write Sequence Values

To tell EclipseLink into which table and column to write the sequence value when an instance of a descriptor's reference class is created, you configure EclipseLink sequencing at the descriptor level.


XML Namespaces

As defined in http://www.w3.org/TR/REC-xml-names/, an XML namespace is a collection of names, identified by a URI reference, which are used in XML documents as element types and attribute names. To promote reusability and modularity, XML document constructs should have universal names, whose scope extends beyond their containing document. XML namespaces are the mechanism which accomplishes this.

XML namespaces are applicable in projects that reference an XML schema: EIS projects that use XML records and XML projects.

For more information, see XML Namespaces Overview].


Project API

This section describes the following:


Project Inheritance Hierarchy

There is only one type of project: org.eclipse.eclipselink.sessions.Project.


XML Namespaces Overview

As defined in http://www.w3.org/TR/REC-xml-names/, an XML namespace is a collection of names, identified by a URI reference, which are used in XML documents as element types and attribute names. To promote reusability and modularity, XML document constructs should have universal names, whose scope extends beyond their containing document. XML namespaces are the mechanism which accomplishes this.

XML namespaces are applicable in projects that reference an XML schema: EIS projects that use XML records and XML projects.

This section describes the following:


Workbench Namespace Resolution

Using Workbench, you can configure the XML schema namespace for your project. For more information, see How to Configure XML Schema Namespace.


Element and Attribute Form Options

The xsd:schema element provides attributes that you can use to specify how elements and attributes should be qualified by namespace.

This section describes the consequences of the following combinations of element and attribute form configuration:


Element Form Default Qualified and Attribute Form Default Unqualified

The XML Schema with Element Form Default Qualified and Attribute Form Default Unqualified example shows an XML schema in which a target namespace is set. It is coded with elementFormDefault set to qualified and attributeFormDefault set to unqualified. This means all elements must be namespace qualified and globally declared attributes must be namespace qualified and locally defined attributes must not be namespace qualified.


XML Schema with Element Form Default Qualified and Attribute Form Default Unqualified

 <?xml version="1.0" encoding="UTF-8"?>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     '''<tt>elementFormDefault="qualified"</tt>''' 
     '''<tt>attributeFormDefault="unqualified"</tt>'''
     xmlns="urn:namespace-example"
     targetNamespace="urn:namespace-example">
     <xsd:element name="customer" type="customer-type"/>
 
     <xsd:complexType name="customer-type">
         <xsd:sequence>
             <xsd:element name="name" type="xsd:string"/>
             <xsd:element ref="date-of-birth"/>
         </xsd:sequence>
         <xsd:attribute name="id" type="xsd:integer"/>
 
     </xsd:complexType>
     <xsd:element name="date-of-birth" type="xsd:date"/>
 </xsd:schema>

This example shows an XML document that conforms to this XML schema.

XML Document

 <?xml version="1.0" encoding="UTF-8"?>
 <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" id="1">
     <'''<tt>ns:</tt>'''name>Jane Doe</'''<tt>ns:</tt>'''name>
     <'''<tt>ns:</tt>'''date-of-birth>1975-02-21</'''<tt>ns:</tt>'''date-of-birth>
 
 </'''<tt>ns:</tt>'''customer>

The XML Descriptors and Mappings example shows the Java code for a Customer class XMLDescriptor and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see Configuring an XML Descriptor and Configuring an XML Mapping).


XML Descriptors and Mappings

 NamespaceResolver namespaceResolver = new NamespaceResolver();
 namespaceResolver.put("ns", "urn:namespace-example");
 
 XMLDescriptor customerDescriptor = new XMLDescriptor();
 customerDescriptor.setJavaClass(Customer.class);
 customerDescriptor.setDefaultRootElement("'''<tt>ns:</tt>'''customer");
 customerDescriptor.setNamespaceResolver(namespaceResolver);
         XMLDirectMapping idMapping = new XMLDirectMapping();
 idMapping.setAttributeName("id");
 idMapping.setXPath("@id");
 customerDescriptor.addMapping(idMapping);
 
 XMLDirectMapping nameMapping = new XMLDirectMapping();
 nameMapping.setAttributeName("name");
 nameMapping.setXPath("'''<tt>ns:</tt>'''name/text()");
 customerDescriptor.addMapping(nameMapping);
 
 XMLDirectMapping birthDateMapping = new XMLDirectMapping();
 birthDateMapping.setAttributeName("birthDate");
 birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 customerDescriptor.addMapping(birthDateMapping);

Element and Attribute Form Default Unqualified

The XML Schema with Element and Attribute Form Default Unqualified example shows an XML schema in which a target namespace is set. It is coded with elementFormDefault and attributeFormDefault set to unqualified. This means that globally defined nodes must be namespace qualified and locally defined nodes must not be namespace qualified.


XML Schema with Element and Attribute Form Default Unqualified

 <?xml version="1.0" encoding="UTF-8"?>
 
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     '''<tt>elementFormDefault="unqualified"</tt>''' 
     '''<tt>attributeFormDefault="unqualified"</tt>'''
     xmlns="urn:namespace-example"
     targetNamespace="urn:namespace-example">
     <xsd:element name="customer" type="customer-type"/>
     <xsd:complexType name="customer-type">
         <xsd:sequence>
 
             <xsd:element name="name" type="xsd:string"/>
             <xsd:element ref="date-of-birth"/>
         </xsd:sequence>
         <xsd:attribute name="id" type="xsd:integer"/>
     </xsd:complexType>
     <xsd:element name="date-of-birth" type="xsd:date"/>
 
 </xsd:schema>

This example shows an XML document that conforms to this XML schema.

XML Document

 <?xml version="1.0" encoding="UTF-8"?>
 <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" id="1">
 
     <name>Jane Doe</name>
     <'''<tt>ns:</tt>'''date-of-birth>1975-02-21</'''<tt>ns:</tt>'''date-of-birth>
 </'''<tt>ns:</tt>'''customer>

The XML Descriptors and Mappings example shows the Java code for a Customer class XMLDescriptor and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see Configuring an XML Descriptor and Configuring an XML Mapping).


XML Descriptors and Mappings

 
 NamespaceResolver namespaceResolver = new NamespaceResolver();
 namespaceResolver.put("ns", "urn:namespace-example");
 
 XMLDescriptor customerDescriptor = new XMLDescriptor();
 customerDescriptor.setJavaClass(Customer.class);
 customerDescriptor.setDefaultRootElement("'''<tt>ns:</tt>'''customer");
 customerDescriptor.setNamespaceResolver(namespaceResolver);
                         XMLDirectMapping idMapping = new XMLDirectMapping();
 idMapping.setAttributeName("id");
 idMapping.setXPath("@id");
 customerDescriptor.addMapping(idMapping);
 
 XMLDirectMapping nameMapping = new XMLDirectMapping();
 nameMapping.setAttributeName("name");
 nameMapping.setXPath("name/text()");
 customerDescriptor.addMapping(nameMapping);
 
 XMLDirectMapping birthDateMapping = new XMLDirectMapping();
 birthDateMapping.setAttributeName("birthDate");
 birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 customerDescriptor.addMapping(birthDateMapping);


Element and Attribute Form Default Qualified

The XML Schema with Element and Attribute Form Default Qualified example shows an XML schema in which a target namespace is set. It is coded with elementFormDefault and attributeFormDefault set to qualified. This means that all nodes must be namespace qualified.


XML Schema with Element and Attribute Form Default Qualified

 <?xml version="1.0" encoding="UTF-8"?>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     '''<tt>elementFormDefault="qualified"</tt>''' 
     '''<tt>attributeFormDefault="qualified"</tt>'''
     xmlns="urn:namespace-example"
     targetNamespace="urn:namespace-example">
     <xsd:element name="customer" type="customer-type"/>
 
     <xsd:complexType name="customer-type">
         <xsd:sequence>
             <xsd:element name="name" type="xsd:string"/>
             <xsd:element ref="date-of-birth"/>
         </xsd:sequence>
         <xsd:attribute name="id" type="xsd:integer"/>
 
     </xsd:complexType>
     <xsd:element name="date-of-birth" type="xsd:date"/>
 </xsd:schema>

This example shows an XML document that conforms to this XML schema.

XML Document

 <?xml version="1.0" encoding="UTF-8"?>
 <'''<tt>ns:</tt>'''customer xmlns:ns="urn:namespace-example" '''<tt>ns:</tt>'''id="1">
     <'''<tt>ns:</tt>'''name>Jane Doe</'''<tt>ns:</tt>'''name>
     <'''<tt>ns:</tt>'''date-of-birth>1975-02-21</'''<tt>ns:</tt>'''date-of-birth>
 
 </'''<tt>ns:</tt>'''customer>

The XML Descriptors and Mappings exampel shows the Java code for a Customer class XMLDescriptor and XML mappings for its attributes to illustrate how this schema configuration affects the XPaths you specify for default root element and mappings (for more information, see Configuring an XML Descriptor and Configuring an XML Mapping).


XML Descriptors and Mappings

 NamespaceResolver namespaceResolver = new NamespaceResolver();
 namespaceResolver.put("ns", "urn:namespace-example");
 
 XMLDescriptor customerDescriptor = new XMLDescriptor();
 customerDescriptor.setJavaClass(Customer.class);
 customerDescriptor.setDefaultRootElement("'''<tt>ns:</tt>'''customer");
 customerDescriptor.setNamespaceResolver(namespaceResolver);
                         XMLDirectMapping idMapping = new XMLDirectMapping();
 idMapping.setAttributeName("id");
 idMapping.setXPath("@'''<tt>ns:</tt>'''id");
 customerDescriptor.addMapping(idMapping);
 
 XMLDirectMapping nameMapping = new XMLDirectMapping();
 nameMapping.setAttributeName("name");
 nameMapping.setXPath("'''<tt>ns:</tt>'''name/text()");
 customerDescriptor.addMapping(nameMapping);
 
 XMLDirectMapping birthDateMapping = new XMLDirectMapping();
 birthDateMapping.setAttributeName("birthDate");
 birthDateMapping.setXPath("'''<tt>ns:</tt>'''date-of-birth/text()");
 customerDescriptor.addMapping(birthDateMapping);

EclipseLink Runtime Namespace Resolution

It is common for an XML document to include one or more namespaces. EclipseLink supports this using its NamespaceResolver. The namespace resolver maintains pairs of namespace prefixes and Uniform Resource Identifiers (URIs). EclipseLink uses these prefixes in conjunction with the XPath statements you specify on EIS mappings to XML records and XML mappings.

Although EclipseLink captures namespace prefixes in the XPath statements for mappings (if applicable), the input document is not required to use the same namespace prefixes. As the XML Descriptors and Mappings example shows, EclipseLink will use the namespace prefixes specified in the mapping when creating new documents.


Namespaces in EclipseLink

Namespaces in EclipseLink



Copyright Statement

Back to the top