[Solved] Hibernate database dialect configuration; no dialect mapping for jdbc type:-9; Rare words

Recently, because rare words are displayed as

The main reason is that this field is of varchar type in the database, and what is displayed is?; Such as Yan; Now the varchar type is changed to nvarchar type; The data can be displayed normally

However, when the springboot program JPA executes the native stored procedure, it will report the following error

After verification, it is due to the dialect configuration problem of Hibernate database; Add database dialect configuration

The dialect needs to be rewritten

package com.winning.thread;

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

public class MyDialect extends SQLServerDialect {
 public MyDialect() {
 super();
 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());
 }
}

Can be displayed normally!

The following two articles are referred to solve:
https://stackoverflow.com/questions/27039300/jpa-sql-server-no-dialect-mapping-for-jdbc-type-9
https://stackoverflow.com/questions/47270883/spring-boot-wont-load-user-defined-dialect

Similar Posts: