hibernate报错:org.hibernate.MappingException: No Dialect mapping for JDBC type: -1

时间:2022-06-23 06:48:33

解决方法:自定义一个Hibernate Dialect.

package com.yourcompany.util ;  

import java.sql.Types;  

import org.hibernate.Hibernate;
import org.hibernate.dialect.MySQL5Dialect; public class CustomDialect extends MySQL5Dialect {
public CustomDialect() {
super();
registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName());
registerHibernateType(-1, Hibernate.STRING.getName());
}
}

然后将hibernate配置文件(或是Spring配置文件)中配置数据库方言的那一项,改成上面自定义的方言

<property name="hibernate.dialect">
com.yourcompany.CustomDialect
</property>