Does Hibernate support Postgres 9.2 Json Data Type?

Hibernate doesn't seem to support the Postgres Json data type.

I get the following error:

javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111

Configuration:

<bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="PGDataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="true" />
                <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
            </bean>
        </property>         
    </bean>

Java Code:

query = "select row_to_json(row) from ( " + query + ") row";

EntityManager em = emf.createEntityManager();

List resultList = em.createNativeQuery(query).getResultList();
System.out.println("resultList " + resultList +  " resultList " + resultList.getClass());

Let me know if there are any workarounds.

+4
source share
1 answer

You can define another property in FactoryBeanunder the name Type Definitions. Where you can provide an explicit class for matching data when it encounters a json data type.

<property name="typeDefinitions">
    <list>
        <bean id="oracleXmlType" class="org.springframework.orm.hibernate3.TypeDefinitionBean">
            <property name="typeName" value="jsonDataType" />
            <property name="typeClass" value="org.test.postgres.JsonDataType" />
        </bean> 
</property>

JSonDataType JSonDataType Java, .

+1

All Articles