4

It looks like Hibernate does not support Postgres Json datatype.

I am getting 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.

ig0774
  • 39,669
  • 3
  • 55
  • 57
user1917034
  • 401
  • 5
  • 11
  • 1
    I'm not familiar with Postgre, why shall you convert the row to JSON, when you need to feed it to ORM? The ORM is more happy with ROW itself. – Amir Pashazadeh Dec 22 '13 at 04:56
  • 1
    possible duplicate of [Mapping postgreSQL JSON column to Hibernate value type](http://stackoverflow.com/questions/15974474/mapping-postgresql-json-column-to-hibernate-value-type) – ig0774 Dec 22 '13 at 05:10

1 Answers1

1

You can define one more property in your FactoryBean called Type Definitions. Where you can provide a explicit class to map the data when it encounters 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>

You need to create a mapping class JSonDataType to map the data from jsonDatatype to appropriate data type in Java or else you can check whether there is an existing mapper class available.

nempoBu4
  • 6,521
  • 8
  • 35
  • 40