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.

2
  • 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. Commented Dec 22, 2013 at 4:56
  • 1
    possible duplicate of Mapping postgreSQL JSON column to Hibernate value type Commented Dec 22, 2013 at 5:10

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.