Search code examples
postgresqlhibernatejpaspring-datajsonb

Define @Type in orm.xml (Spring Data / JPA 2.1 /Hibernate 5.3.7/Postgresql)?


We need to perform CRUD operations on an object in Postgresql that has a jsonb field. I understand that we can create a user type and annotate them with @Type(type = "jsonb") in the model. However, we want to define mapping of meta data in orm.xml instead of annotations. We have tried to use a converter as well but still have no success. Is there a possibility to achieve this with orm.xml and how? Thanks.


Solution

  • @Type is not part of JPA specification. It is Hibernate specific.

    Alternative to JPA annotation is orm.xml.

    Alternative for Hibernate annotation is hbm.xml - hibernate mapping file.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 
    
    <hibernate-mapping>
        <class name="" table="">
            <id></id>
            <property>
                <type name="">
                </type>
            </property>
        </class>
    </hibernate-mapping>