I want to store XML data in an Oracle XMLType column with registered XML schema file. Both XML files and the XSD schema are valid and XMLs conform to the schema. To get Hibernate work with XMLType, I used the Hibernate mapping Document-XMLType which can be found here:
http://solecjj.blogspot.com/2011/02/hibernate-with-oracle-xmltype.html
My Hibernate mapping XML looks like this:
...
<hibernate-mapping>
<class name="cz.zcu.kiv.eegdatabase.data.pojo.ScenarioType1" schema="JPERGLER" table="SCENARIO_TABLE_1">
<id name="scenarioId" type="int">
<column name="SCENARIO_ID" precision="22" scale="0"/>
<generator class="increment"/>
</id>
<property name="scenarioXml" type="cz.zcu.kiv.eegdatabase.data.datatypes.OracleXMLType">
<column name="SCENARIO_XML"/>
</property>
</class>
</hibernate-mapping>
And this is the corresponding POJO class:
public ScenarioType1() {
}
public ScenarioType1(int scenarioId, Document scenarioXml) {
this.scenarioId = scenarioId;
this.scenarioXml = scenarioXml;
}
public int getScenarioId() {
return scenarioId;
}
private void setScenarioId(int scenarioId) {
this.scenarioId = scenarioId;
}
public Document getScenarioXml() {
return scenarioXml;
}
public void setScenarioXml(Document scenarioXml) {
this.scenarioXml = scenarioXml;
}
The document object is created in a controller class and is handed over the DAO object as an attribute of its POJO object:
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException bindException)
throws Exception {
MultipartFile xmlFile = data.getDataFileXml();
ScenarioType1 scenarioType1;
scenarioType1 = new ScenarioType1();
...
if ((xmlFile != null) && (!xmlFile.isEmpty())) {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
InputStream inputStream = xmlFile.getInputStream();
Document doc = docBuilder.parse(inputStream);
scenarioType1.setScenarioXml(doc);
inputStream.close();
}
scenarioTypeDao.create(scenarioType1);
...
}
The DAO class and interface are very simple:
public interface ScenarioTypeDao extends GenericDao<ScenarioType1, Integer> {
}
public class SimpleScenarioTypeDao extends SimpleGenericDao<ScenarioType1, Integer>
implements ScenarioTypeDao {
public SimpleScenarioTypeDao() {
super(ScenarioType1.class);
}
}
When the method onSubmit() in the controller class is processed, I get the following error message:
Hibernate: insert into JPERGLER.SCENARIO_TABLE_1 (SCENARIO_XML, SCENARIO_ID) values(?,?)
SEVERE: Servlet.service() for servlet dispatcher threw exception org.springframework.dao.CleanupFailureDataAccessException: Failed to flush session before close: Could not execute JDBC batch update; nested exception is org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
...
Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.jav开发者_StackOverflowa:126) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
...
Caused by: java.sql.BatchUpdateException: ORA-31011: XML parsing failed
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:566) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9365) at oracle.jdbc.driver.OracleStatementWrapper.executeBatch (OracleStatementWrapper.java:210) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
It looks that the created Document object is filled with correct data, so the error seems to happen on the Hibernate mapping side. I'm starting to feel desperate, any help would be appreciated.
This is the sample XML file I'm trying to insert:
<?xml version="1.0"?>
<scenarios>
<scenario name="P300" src="p300.xml"/>
<scenario src="070608_p300.xml" name="070608_p300" />
<scenario src="cisla_070608.xml" name="cisla_070608" />
</scenarios>
精彩评论