Hibernate PostgreSQL JSONB issue: No Dialect mapping for JDBC type: 1111

Hi, I have jsonb data type stored in postgres. I want to retrieve a field from jsonb data using hibernate. My hibernate query is correctly formed and when I execute it directly on postgre, it runs correctly and gives me the result. But when I execute through HIbernate, I get bind error.
Hibernate 5.2
Postgre 9.4

Stack Trace:

There’s no stack-trace attached, so I assume you got the No Dialect mapping for JDBC type: 1111 error.

First, Hibernate does not support JSON natively, so you might want to check out the hibernate-types project which offers this functionality.

Second, the 1111 code stands for Types.OTHER, so you might want to register that to the jsonb type.

For that, you can either use a custom Dialect:

public class PostgreSQL95JsonDialect 
        extends PostgreSQL95Dialect {
 
    public PostgreSQL95JsonDialect() {
        super();
        this.registerHibernateType(
            Types.OTHER, JsonNodeBinaryType.class.getName()
        );
    }
}

Or, at native SQL query level:

JsonNode properties = (JsonNode) entityManager
.createNativeQuery(
    "SELECT properties " +
    "FROM book " +
    "WHERE isbn = :isbn")
.setParameter("isbn", "978-9730228236")
.unwrap(org.hibernate.query.NativeQuery.class)
.addScalar("properties", JsonNodeBinaryType.INSTANCE)
.getSingleResult();

Check out this article for more details about how you can register a custom JDBC Type to a Hibernate Type.

Vlad, first thanks for the library and I was wondering if you see jsonb officially being supported by Hibernate in the future.

Thanks again

I wish it will be integrated in future as well.

Yes, we all wish lots of things regarding Hibernate but they just won’t happen…

Hibernate does not offer a JSON types because JSON is not supported by all DB dialects supported by Hibernate. However, Hibernate Types is actively maintained, and it works like a charm, so there’s no reason to complain about not having it integrated in Hibernate Core.

More, Hibernate is open-source, so if you wish a lot of things regarding it, you should start contributing, like I do. I develop Hibernate Types in my own free time. So, what holds you back?