Hibernate映射数据库中longtext类型属性时报错No Dialect mapping for JDBC type: -1的解决方案

时间:2023-03-08 16:30:23

出现错误的原因是:hibernate中对于数据库的longtext数据类型不支持。

解决方案:

1、写个类集成方言,然后自己实现对longtext的支持

 import java.sql.Types;
import org.hibernate.dialect.MySQL5Dialect;
public class DialectForInkfish extends MySQL5Dialect {
public DialectForInkfish() {
super();
registerHibernateType(Types.LONGVARCHAR, 65535, "longtext");
}
}

2、修改hibernate.cfg.xml配置文件

将<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>  改为<property name="dialect">com.ibm.crl.inkfish.config.DialectForInkfish</property>