How to use Oracle XMLType in Hibernate

  • Edit your Hibernate Mapping XML

<?xml version=”1.0″?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd” >

<hibernate-mapping>

<class
name=”mypackage.MyClass”
table=”MYTABLE”
>

<id
name=”myId”
type=”java.lang.Long”
column=”MY_ID”
>

<generator class=”sequence”>
<param name=”sequence”>my_id_seq</param>
</generator>

</id>

<property
name=”myXml”
type=”mypackage.HibernateXMLType”
column=”MY_XML”
/>

</class>

</hibernate-mapping>

  • Edit your Java Persistence Object

public class MyClass implements Serializable {

private Document myXml;

public Document getMyXml() {
return myXml;
}

public void setMyXml(Document messageXml) {
this.myXml = messageXml;
}
}

  • Add required JARS
    You would need xdb.jar, xmlparserv2.jar, and ojdbc14.jar

Continue reading