Getting org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111 using com.vladmihalcea:hibernate-types-5

Drew Wills picture Drew Wills · Jun 25, 2018 · Viewed 8.1k times · Source

I'm attempting to use this library for persisting JSON with JPA & Hibernate:

https://github.com/vladmihalcea/hibernate-types

I am following (in every meaningful detail) the examples from this article:

https://vladmihalcea.com/how-to-store-schema-less-eav-entity-attribute-value-data-using-json-and-hibernate/

Here is my (Gradle) dependency:

compile 'com.vladmihalcea:hibernate-types-5:2.2.2'

And here is the source of my entity class:

package org.apereo.portal.fbms.data;

import com.fasterxml.jackson.databind.JsonNode;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "FBMS_FORM")
@TypeDef(
        name = "json",
        typeClass = JsonStringType.class
)
public class FormEntity {

    @Id
    @GeneratedValue
    private Long id;

    @Column(name = "FNAME", nullable = false, unique = true)
    private String fname; // TODO:  Regex-based validator

    @Column(name = "VERSION", nullable = false)
    private int version;

    @Column(name = "SCHEMA", nullable = false)
    @Type(type = "json")
    private JsonNode schema;

    @Column(name = "METADATA")
    @Type(type = "json")
    private JsonNode metadata;

    public Long getId() {
        return id;
    }

    // Additional getters and setters omitted for brevity...

}

I am getting this exception:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-4.3.16.RELEASE.jar:4.3.16.RELEASE]
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:371) ~[spring-orm-4.3.16.RELEASE.jar:4.3.16.RELEASE]
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:336) ~[spring-orm-4.3.16.RELEASE.jar:4.3.16.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1688) ~[spring-beans-4.3.16.RELEASE.jar:4.3.16.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1626) ~[spring-beans-4.3.16.RELEASE.jar:4.3.16.RELEASE]
        ... 16 common frames omitted
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
        at org.hibernate.dialect.TypeNames.get(TypeNames.java:70) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.dialect.TypeNames.get(TypeNames.java:101) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.dialect.Dialect.getTypeName(Dialect.java:341) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.mapping.Column.getSqlType(Column.java:231) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.mapping.Table.sqlAlterStrings(Table.java:464) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.migrateTable(SchemaMigratorImpl.java:254) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:170) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
        at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.16.RELEASE.jar:4.3.16.RELEASE]
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:360) ~[spring-orm-4.3.16.RELEASE.jar:4.3.16.RELEASE]
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:384) ~[spring-orm-4.3.16.RELEASE.jar:4.3.16.RELEASE]
        ... 20 common frames omitted

In case it's helpful...

  • I haven't included info on RDBMS platform or JDBC driver; that's intentional -- the solution needs to be database platform-independent.
  • I will be using spring-data-jpa with this entity.

Answer

GROX13 picture GROX13 · Sep 21, 2019

Way to solve this, in my case, was adding custom hibernate dialect. This resource might be helpful. Create custom dialect class:

// CustomPostgreSQLDialect.java
public class CustomPostgreSQLDialect extends PostgreSQL10Dialect {

    public CustomPostgreSQLDialect() {
        super();
        registerHibernateType(Types.OTHER, StringArrayType.class.getName());
        registerHibernateType(Types.OTHER, IntArrayType.class.getName());
        registerHibernateType(Types.OTHER, JsonStringType.class.getName());
        registerHibernateType(Types.OTHER, JsonBinaryType.class.getName());
        registerHibernateType(Types.OTHER, JsonNodeBinaryType.class.getName());
        registerHibernateType(Types.OTHER, JsonNodeStringType.class.getName());
    }
}

and will need to register your custom dialect in properties

# application.yml
spring:
  jpa:
    properties:
      hibernate:
        dialect: "com.test.CustomPostgreSQLDialect"

and if you need to provide the custom CustomPostgreSQLDialect via the hibernate.dialect configuration property:

<property
    name="hibernate.dialect"
    value="com.test.CustomPostgreSQLDialect"
/>