Hibernate 数据库方言配置;no dialect mapping for jdbc type:-9;生僻字
最近因为生僻字在界面上显示为?;
主要原因是该字段在数据库中就是varchar类型,显示的就是?;如䶮(yan);现把varchar类型改为nvarchar类型;数据中能够正常显示;
但是SpringBoot程序jpa执行原生的存储过程的会报如下错误;
经验证,是因为Hibernate数据库方言配置问题;增加数据库方言配置
,方言需要重写:
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());
}
}
能够正常显示!
参考如下两篇文章解决,感谢大神:
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