org.hibernate.MappingException: No Dialect mapping for JDBC type


Here I am going to show you how to resolve issue org.hibernate.mapping.exception: No Dialect mapping for JDBC type that occurs in your Hibernate based application due to some types mismatch between database table column and Java field.

You might have seen similar kind of exception occurred during performing native queries without entity class and this kind of issue may have been occurred in different databases such as MySQL, Oracle, SQL Server, PostgreSQL etc. Depending upon the database vendor you will get error for JDBC types -4, -9, 7 or 2003 etc.

It means that Hibernate is unable to implement a type mapping for database type (for example, table column type float) to Java type (float) though float type is listed in the JDBC reference.


Oracle Database, Hibernate, JPA, Spring Boot


Here I will create an example how to query Oracle database without entity class using Hibernate JPA and in what situation it throws the exception org.hibernate.MappingException: No Dialect mapping for JDBC type: -9.

In this example I will also show you how to resolve the issue – org.hibernate.MappingException: No Dialect mapping for JDBC type.

I assume that you are using Hibernate JPA with Spring Boot application.

Spring Configuration

Let’s say you have the following configurations for your Oracle database connections and you have defined few beans for DataSource, EntityManager and TransactionManager as shown in the following configuration class.

Make sure your have the correct database URL, user name and password in the following database configurations.

@EnableJpaRepositories(basePackages = "com.roytuts.jparepo")
public class OracleDbConfig {
	public DataSource dataSource() throws SQLException {
		OracleDataSource dataSource = new OracleDataSource();
		return dataSource;
	public EntityManagerFactory entityManagerFactory() throws SQLException {
		HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
		LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
		return factory.getObject();
	public PlatformTransactionManager transactionManager() throws SQLException {
		JpaTransactionManager txManager = new JpaTransactionManager();
		return txManager;

Spring Repository

Let’s say you have the following DAO class in order to perform database query to fetch something. Notice here I don’t have any Entity class or Spring JpaRepository interface API used. I am using here native query to fetch data from database.

public class UserGroupRepo {
	private EntityManagerFactory entityManagerFactory;
	public String getUserGroup() {
		Query groups = entityManagerFactory.createEntityManager().createNativeQuery(
										"SELECT GROUP_NAME FROM USER_GROUP WHERE EMAIL='[email protected]'");
		return (String) groups.getSingleResult();


Now when you call the above getUserGroup() method from other class (service, controller, component, etc.) you will get below exception.

In the next section we will analysis what went wrong with the above code in getUserGroup() method.

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: -9] with root cause
org.hibernate.MappingException: No Dialect mapping for JDBC type: -9
                at org.hibernate.dialect.TypeNames.get(
                at org.hibernate.dialect.TypeNames.get(
                at org.hibernate.dialect.Dialect.getHibernateTypeName(
                at org.hibernate.loader.custom.JdbcResultMetadata.getHibernateType(
                at org.hibernate.loader.custom.ScalarResultColumnProcessor.performDiscovery(
                at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(
                at org.hibernate.loader.Loader.getResultSet(
                at org.hibernate.loader.Loader.executeQueryStatement(
                at org.hibernate.loader.Loader.executeQueryStatement(
                at org.hibernate.loader.Loader.doQuery(
                at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(
                at org.hibernate.loader.Loader.doList(
                at org.hibernate.loader.Loader.doList(
                at org.hibernate.loader.Loader.listIgnoreQueryCache(
                at org.hibernate.loader.Loader.list(
                at org.hibernate.loader.custom.CustomLoader.list(
                at org.hibernate.internal.SessionImpl.listCustomQuery(
                at org.hibernate.internal.AbstractSessionImpl.list(
                at org.hibernate.internal.SQLQueryImpl.list(
                at org.hibernate.jpa.internal.QueryImpl.list(
                at org.hibernate.jpa.internal.QueryImpl.getSingleResult(
                at com.roytuts.dao.UserGroupRepo.getUserGroup(

What went wrong?

In the above example you see you don’t have any entity class for our USER_GROUP table but we are querying database table directly without using entity class and Spring’s JpaRepository interface.

Therefore Hibernate framework is not able to map the database table’s column data type to Java type. That’s is why you are getting such exception.

Even if we create our custom query, then also you need to use entity class and JpaRepository to query database table in order to get the expected results. But here you are neither using entity class nor JpaRepository interface to query database.

The next step would be to resolve this issue. The answer to this problem is to write a custom dialect and set it to vendorAdapter object using method setDatabasePlatform().

Custom Dialect

Here we I am going to write custom dialect to resolve the issue.

package com.roytuts.dialect;

import java.sql.Types;
import org.hibernate.dialect.Oracle12cDialect;
import org.hibernate.type.StandardBasicTypes;

public class CustomDialectOracle extends Oracle12cDialect {

	public CustomDialectOracle() {
		registerHibernateType(Types.NCHAR, StandardBasicTypes.CHARACTER.getName());
		registerHibernateType(Types.NCHAR, 1, StandardBasicTypes.CHARACTER.getName());
		registerHibernateType(Types.NCHAR, 255, StandardBasicTypes.STRING.getName());
		registerHibernateType(Types.NVARCHAR, StandardBasicTypes.STRING.getName());
		registerHibernateType(Types.LONGNVARCHAR, StandardBasicTypes.TEXT.getName());
		registerHibernateType(Types.NCLOB, StandardBasicTypes.CLOB.getName());


In the above code you see I have extended the class Oracle12cDialect because I am using Oracle 12C, but here you have to extend the class according to your database vendor and version.

Now update the below code snippets.


HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();


HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();

Now executing the query again, you will get the expected result.

Thanks for reading.

Related posts

One Thought to “org.hibernate.MappingException: No Dialect mapping for JDBC type”

  1. Anand

    Thanks for saving my time, Soumitra. Well explained.

Leave a Comment