XML Mapping Syntax
The mapping file that the previous example used is different from the Hibernate 2 mapping file. Hibernate 3 introduced several new mapping types specific to XML persistence.
The central new mapping attribute is a
node, which relates either to the element within an XML document or to the attributes in the document that are to be mapped.
A "node" can represent a mapping of the following:
"element-name": In the case study, this would be expressed as a node="product" for a <product></product> element.
"@attribute-name": In the example, node="@sku" would map to an XML attribute <product sku="1001001">.
Period ("."): This maps to the parent of the element (like <products> as a parent of the <product>).
"element-name/@attribute-name": These map to the attribute of the named element (product/@sku).
XML Persistence Not Hibernate's Main Mission
Release 3 of the Hibernate framework effectively closes the cycle on the most common persistence methods available today (excluding only LDAP). Java community now has a framework that provides an efficient and consistent method for effortless OR and XML persistence.
With that in mind, understanding the Hibernate project's mission is important. Even though the Hibernate 3 XML features are highly useful and attractive, they are not meant to replace the most popular XML marshalling or transformation frameworks. Despite a very comprehensive OR mapping solution, Hibernate is not expected to grow into a major XML manipulation framework (per Hibernate author Gavin King, TheServerSide Java Symposium 2005).
For that reason, you should take the XML persistence features as helpful extensions to the already powerful Hibernate framework, which enable you to easily incorporate another contemporary data representation mechanism into your application. If you have to deal with intricate integration and transformation scenarios, however, look into XML-specific frameworks.