Stacktraces org.hibernate.MappingException: No Dialect mapping for JDBC type: -4 org.hibernate.dialect.TypeNames.get(TypeNames.java:56) org.hibernate.dialect.TypeNames.get(TypeNames.java:81) org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:370) org.hibernate.loader.custom.CustomLoader$Metadata.getHibernateType(CustomLoader.java:559) org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.performDiscovery(CustomLoader.java:485) org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:501) org.hibernate.loader.Loader.getResultSet(Loader.java:1796) org.hibernate.loader.Loader.doQuery(Loader.java:674)
问题还原:
数据库为MySQL,读取表中一个Blog类型字段
String hql ="select ID,IMG from test"; Session session = getSession(); list = session.createSQLQuery(hql).list();
问题解决:
这是由于mysql(BLOB或text)在hibernate中没有注册该类型
重写MySQL方言,新建一个类
import java.sql.Types; import org.hibernate.Hibernate; import org.hibernate.dialect.MySQLDialect; public class BlobMySQLDialect extends MySQLDialect{ public BlobMySQLDialect () { super(); registerHibernateType(Types.LONGVARBINARY, Hibernate.BLOB.getName()); } }
<property name="dialect">org.hibernate.dialect.MySQLDialect</property> 修改为: <property name="dialect">该类所在路径/BlobMySQLDialect</property>
作者:itmyhome
org.hibernate.MappingException: No Dialect mapping for JDBC type: -4
原文地址:http://blog.csdn.net/itmyhome1990/article/details/46462713