tags:

views:

72

answers:

2

How to persist XMLType column via JPA/Hibernate? As per oracle documentation, there are two ways in declaring storage clause for XMLType. They are, LOB and Object-Relational. I dont want to go with LOB. I have schema and register into database. I have not have example on how to design my Entity for XMLType. Does any one know please share it?

A: 

I would use a custom UserType (Hibernate extension). The blog post Hibernate with Oracle XmlType provides an implementation that you might reuse. Then, declare your custom UserType with the Type annotation.

Pascal Thivent
Thanks. But I got this below SQL exception when I try to persist through JPA entitymanager. I have done exactly what you provided in your blogs>created hibernate usertype class>entity pointing to @Type("HibernateXMLType")>Document as fieldSQL Exception-------------java.sql.SQLException: Could not convert Document to String for storage
Moorthy
@Moorthy: Please update your question with the problem, it's unreadable in the comment box.
Pascal Thivent
The oracle xml parser xmlparserv2.jar is causing the issue. If I remove it, HibernateXMLType class throws the below exception from the line xmlType = XMLType.createXML(st.getConnection(),..)java.lang.NoClassDefFoundError: oracle/xml/parser/v2/XMLParseException at com.tutorial.hibernate.HibernateXMLType.nullSafeSet(HibernateXMLType.java:112)I know this parser conflict with javax.xml..parserPlease throw some light on this how to resolve it.
Moorthy
I have resolved it.
Moorthy
@Moorthy: Good. Feel free to accept this answer then :)
Pascal Thivent
A: 

The custom java class HibernateXMLType works fine for CLOB.

Moorthy