I'm trying to demonstrate or disprove the feasibility of using a Hibernate user type that is stored as
org.w3c.dom.Document on the Java side and Oracle's XMLType in the database. I'm basing my code on the example at
http://community.jboss.org/wiki/MappingOracleXmlTypeToDocument.
Using Hibernate 3.6.0 Final and the Oracle 10g driver, "xdb.jar" and "xmlparserv2.jar", my code works for simple XML of the sort I expect to persist. (It does not work when the top-level tag is <html>; I'll post details of that issue elsewhere.) Swapping in the corresponding driver and two JAR files from Oracle 11g, I get the following error:
Code:
438 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (31) : http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd<Line 31, Column 2>: XML-20068: (Fatal Error) content model is not deterministic
Initial SessionFactory Creation failed. org.hibernate.InvalidMappingException: Unable to read XML
Exception in thread "main" java.lang.ExceptionInInitializerError
at demo.hr.HibernateUtil.buildSessionFactory(HibernateUtil.java:34)
at demo.hr.HibernateUtil.<clinit>(HibernateUtil.java:15)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at demo.hr.AddDoc.main(AddDoc.java:54)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)
at org.hibernate.cfg.Configuration.add(Configuration.java:510)
at org.hibernate.cfg.Configuration.add(Configuration.java:506)
at org.hibernate.cfg.Configuration.add(Configuration.java:686)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:771)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.jav
a:2314)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.jav
a:2280)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2260)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2213)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
at demo.hr.HibernateUtil.buildSessionFactory(HibernateUtil.java:20)
... 4 more
Caused by: org.dom4j.DocumentException: Error on line 31 of document http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd : http://hibernate.sourceforge.n
et/hibernate-mapping-3.0.dtd<Line 31, Column 2>: XML-20068: (Fatal Error) content model is not deterministic Nested exception: http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd<Line 31, Column 2>: XML-20068: (Fatal Error) content model is not deterministic
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:75)
... 15 more
My "hibernate.cfg.xml" file is as follows:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">HR</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ORACLASS</property>
<property name="hibernate.connection.username">HR</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.show_sql">true</property>
<mapping class="demo.hr.DocBean" resource="demo/hr/DocBean.hbm.xml"/>
</session-factory>
</hibernate-configuration>
(Hibernate also prints a warning about an "obsolete hibernate namespace", but that's what JBoss Tools produced...)
Here's the one mapping file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="demo.hr">
<class name="DocBean" table="docs">
<id name="id" type="int" access="field" >
<generator class="sequence-identity">
<param name="sequence">seq</param>
</generator>
</id>
<property generated="never" lazy="false" name="content" type="demo.hr.OracleXMLUserType" access="field" />
</class>
</hibernate-mapping>
Has anyone seen this? Does anyone know of an appropriate workaround, other than reverting to the Oracle 10g drivers?