If your database supports Extensible Markup Language (XML) column types, you can use mapping tools to manage XML objects. You have the choice of mapping XML columns to a Java string or a Java byte array field.
JPA for the application server supports the management of XML objects by using a third-party solution for mapping management. These mapping techniques make using the XML objects as strings or byte arrays difficult.
DB2®, Oracle, and SQLServer databases support XML column types, XPath queries, and indices over these columns.
Persistent properties to XML mapping
An embedded class with XML column support must use XML marshaling to write the data to the XML column and unmarshalling to retrieve the data from the XML column. The path expressions and predicates over the embedded class are converted to XML predicates, XPATH expressions, or XQuery expressions and are written to the database.
WebSphere Application Server supports JPA applications to use a third-party tool for XML mapping. This is done through the extension points for custom field mappings. The third-party mapping tool uses the extension points by providing a custom value handler for the persistent fields that are mapped to the XML columns. In OpenJPA, this value handler is named org.apache.openjpa.xmlmapping.XmlValueHandler and this handler requires the @Strategy annotation on the Java field that is mapped to the XML column.
@Entity
public class Order {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
int oid;
@Persistent
@Strategy("org.apache.openjpa.xmlmapping.XmlValueHandler")
@Column(name="shipaddr")
Address shipAddress;
…
The OpenJPA mapping tool generates a SHIPADDR column with XML type in the table definition for ORDER table.