How to fix the Hibernate “No Dialect mapping for JDBC type” issue

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!


Recently, stumbled on this question on the Hibernate forum, and since I’ve been seeing it before on StackOverflow and bumped into it myself while working with JPA and Hibernate, I decided to turn the answer into an article.

Therefore, in this article, you are going to find out how you can fix the “No Dialect mapping for JDBC type” Hibernate issue.

Domain Model

Considering we have a Book entity that defines a properties attribute which is associated with a JSON column in the database.

The Book entity can be mapped as follows:

@Entity(name = "Book")
@Table(name = "book")
    name = "jsonb-node", 
    typeClass = JsonNodeBinaryType.class
public class Book {

    private Long id;

    private String isbn;

    @Type(type = "jsonb-node")
    @Column(columnDefinition = "jsonb")
    private JsonNode properties;

    //Getters and setters omitted for brevity

The JsonNodeBinaryType is provided by the hibernate-types project, so if you want to persist JSON properties, you don’t need to write your own Hibernate Types.
Just add the hibernate-types dependency to your project and map the JSON properties accordingly.

Persisting and fetching the Book entity

Now, let’s assume we have added the following Book entity in our database:

Book book = new Book();
        "{" +
        "   \"title\": \"High-Performance Java Persistence\"," +
        "   \"author\": \"Vlad Mihalcea\"," +
        "   \"publisher\": \"Amazon\"," +
        "   \"price\": 44.99" +


When persisting the Book entity, Hibernate will issue the proper SQL INSERT statement:

        "title":"High-Performance Java Persistence",
        "Vlad Mihalcea",

Now, we fetching the Book entity by its natural identifier, we can see that the properties JSON attribute is fetched as a JsonNode:

Book book = entityManager

    "High-Performance Java Persistence", 

Fetching the JSON attribute using JPQL

Now, if we want to fetch the properties entity attribute using JPQL, we can execute the following query:

JsonNode properties = entityManager
    "select " +
    "from Book b " +
    "where b.isbn = :isbn", JsonNode.class)
.setParameter("isbn", "978-9730228236")

    "High-Performance Java Persistence", 

And everything works properly since the JPQL query is parsed and the underlying Hibernate Type that handles the properties attribute is going to be known when building the result.

Fetching the JSON attribute using native SQL

However, if we try to do the same using a native SQL query:

JsonNode properties = (JsonNode) entityManager
    "SELECT properties " +
    "FROM book " +
    "WHERE isbn = :isbn")
.setParameter("isbn", "978-9730228236")

    "High-Performance Java Persistence",

Hibernate will throw the following MappingException:

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

The 1111 JDBC type corresponds to Types.OTHER which is what the PostgreSQL JDBC Driver uses for jsonb column types.

Mapping Types.OTHER to JsonNodeBinaryType

There are several ways you can address this issue. You can register a Hibernate Type to handle the JDBC Types.OTHER either globally or on a per-query basis.

Mapping the JDBC Types.OTHER to JsonNodeBinaryType at the Dialect level

You can map a given JDBC Type code to a Hibernate Type using the database-specific Dialect.

Therefore, for PostgreSQL, we could define a PostgreSQL95JsonDialect that looks as follows:

public class PostgreSQL95JsonDialect 
        extends PostgreSQL95Dialect {

    public PostgreSQL95JsonDialect() {
            Types.OTHER, JsonNodeBinaryType.class.getName()

And if we provide the custom PostgreSQL95JsonDialect via the hibernate.dialect configuration property:


The native SQL query will run just fine.

Mapping the JDBC Types.OTHER to JsonNodeBinaryType at the NativeQuery level

Another option is to provide Hibernate Type associated with the current JDBC ResultSet:

JsonNode properties = (JsonNode) entityManager
    "SELECT properties " +
    "FROM book " +
    "WHERE isbn = :isbn")
.setParameter("isbn", "978-9730228236")
.addScalar("properties", JsonNodeBinaryType.INSTANCE)

    "High-Performance Java Persistence",

Notice the addScalar method call which provides the Hibernate Type to be used when handling the Types.Other JDBC column type.

That’s it!

If you enjoyed this article, I bet you are going to love my Book and Video Courses as well.


Handling the No Dialect mapping for JDBC type issue is not very complicated, and it can be done either globally or on a per-query basis.


10 Comments on “How to fix the Hibernate “No Dialect mapping for JDBC type” issue

  1. I ran into a similar issue today when I tried implementing an
    AttributeConverter<YearMonth, Instant>

    What I had to do instead was implement
    AttributeConverter<YearMonth, Timestamp>

    where Timestamp is the native java.sql.Timestamp, which hibernate understands by default

  2. Hi Vlad,

    I used the query SELECT properties FROM public.customer WHERE properties @>[{“key1″:”value1”}]; This works fine. But I would like to parameterize like u provided in example in blog like JsonNode properties = (JsonNode) entityManager
    “SELECT properties ” +
    “FROM book ” +
    “WHERE isbn = :isbn”)
    .setParameter(“isbn”, “978-9730228236”)
    .addScalar(“properties”, JsonNodeBinaryType.INSTANCE)

    Can we do parameterized query for json array. could you please point me to example implementation.


  3. Hi Vlad,

    Thanks, This works. I am trying a different scenario. Is it possible to query key values in a json array.
    For example if the jsonb data stored is [{“key1″:”value1”},{“key2″:”value2”}].

    • Sure thing. Just use a native SQL query if the database supports the feature.

  4. I use Wildfly (Hibernate 5.3.x), PostegreSQL 10 and I have table columns with PostgreSQL-specific ‘uuid’ and ‘jsonb’ data types.
    Depending on the situation (query complexity, jsonb involved or not, etc.) I need to be able to use all kinds of JPA queries via the JEE EntityManager i.e. native queries, JPQL queries and (maybe) CriteriaAPI queries.
    Probably my question below is answered in various articles or SO answers but sincerely I am lost with it.
    Could you be so kind as to share which Hibernate types (either the Hibernate built-ins or yours from hibernte-types-52) should I register and which should be the corresponding Java data types on the @Entity class in order to have an as effecient as possible data transfer from Java to PostgreSQL

    Many thanks,

    • For entity queries, Hibernate will use the entity mappings, meaning that @TypeDef will automatilaly do the trick. For native SQL, it’s not possible to know what Types.OTHER is supposed to mean, so use addScalar as explained in this article.

      • So the problem with registering the types with Hibernate is that PostgreSQL uses Types.OTHER and we can’t register uuid and jsonb at the same time?
        Could that be argued with the Postgres JDBC driver community because it seems like a shortcoming?

      • The problem is JDBC defines the Types.OTHER for everything else not supported natively. Now, if PostgreSQL JDBC Driver used different codes like other RDBMS do (e.g. OracleTypes), it would be easier to fix this issue indeed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.