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
2010-06-17 19:57:10
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
2010-06-17 23:44:25
@Moorthy: Please update your question with the problem, it's unreadable in the comment box.
Pascal Thivent
2010-06-18 00:03:04
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
2010-06-18 17:30:39
I have resolved it.
Moorthy
2010-06-18 21:14:32
@Moorthy: Good. Feel free to accept this answer then :)
Pascal Thivent
2010-06-18 21:34:17