We will see how to resolve issue org.hibernate.mapping.exception: No Dialect mapping for JDBC type. 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

@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

Create below DAO class in order to perform database query to fetch something. Notice here we don’t have any Entity class or Spring JpaRepository interface API is used.

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();


When you call the above getUserGroup() method from other class you will get below exception

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 we 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 is not able to map the database column data type to java type. That’s is why we are getting such exception. Even if we create our custom query, then also we need to use entity class and JpaRepository to query database table in order to get expected results. But here we are neither using entity class nor JpaRepository interface to query database. The next step is, how we will resolve this issue. The answer is writing custom dialect and set it to vendorAdapter object using method setDatabasePlatform().

Writing Custom Dialect

Here we will 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 T have extended the class Oracle12cDialect 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 execute the query again, you will get the expected result.

Thanks for reading.


1 thought on “org.hibernate.MappingException: No Dialect mapping for JDBC type

Comments are closed.