How to map XMLType with JPA/Hibernate

0 votes
asked Jun 17, 2010 by moorthy

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?

4 Answers

0 votes
answered Jun 14, 2010 by moorthy

The custom java class HibernateXMLType works fine for CLOB.

0 votes
answered Jun 17, 2010 by pascal-thivent

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.

0 votes
answered Jun 21, 2011 by basanth-roy
0 votes
answered Jun 30, 2016 by ametzaga

This is working fine for me (JPA 2.1 and Hibernate 5.1.0):

  • Create the field in the entity as a String.
  • Use the @ColumnTransformer annotation from Hibernate to define how to read and write from the column.
  • Set the columnDefinition in @Column as "XMLType"

    @ColumnTransformer(read = "to_clob(columnName)", write = "?")
    @Column(name = "COLUMN_NAME", columnDefinition = "XMLType")
    private String columnName;

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...