错误如下:
org.springframework.orm.hibernate3.HibernateSystemException: No Dialect mapping for JDBC type: -1; nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:690)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
解决办法:
========================
public class MySQL5DialectExtends extends MySQLDialect {
public MySQL5DialectExtends() {
super();
//registerColumnType(Types.LONGVARCHAR, 65535, "text"); 不管用
registerHibernateType(Types.LONGVARCHAR, 65535, "text");
}
}
========================
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
com.welearning.engine.config.java.MySQL5DialectExtends
</prop>
========================
MySQL JAVASQL Hibernate 这里有三个关系。
javasql要把无论什么数据库映射过去。应该是这个一个关系 DB(Mysql,oracle) javasql ORM(mybatis hibernate)
其中MySQL <typeNames> JAVASQL <hibernateTypeNames> Hibernate
typeNames和hibernateTypeNames 数据类型是下面两个(在Dialect.java中)其中Key(int java.sql.Type中) value(String)
private final TypeNames typeNames = new TypeNames();
private final TypeNames hibernateTypeNames = new TypeNames();
待续:
==========================下面是我debug时候的笔记,杂七杂八的。
doQuery 执行查询 Loader.java
getResultSet 做结果映射
autoDiscoverTypes 对应到结果的每一列。
hibernate会用查询到数据库的列去对应自己的类型 比如 查询的id对应一个org.hibernate.type.IntegerType
originalColumnName=body,mysqlType=253(FIELD_TYPE_VAR_STRING)
hibernateTypeNames中存放这hibernate支持的类型 比如 4对应"integer"
{1=character, 2=big_decimal, 3=big_decimal, 4=integer, 5=short, 2004=blob, 6=float, 7=float, 2005=clob, 8=double, 12=string, 93=timestamp, -7=boolean, 92=time, -6=byte, -5=big_integer, -3=binary, -2=binary, 91=date}
注意 这里没有text
==
typeNames
{1=char(1), 2=decimal($p,$s), 4=integer, 5=smallint, 2004=longblob, 6=float, 2005=longtext, 8=double precision, 12=longtext, 93=datetime, -7=bit, 92=time, -6=tinyint, -5=bigint, -3=longblob, 91=date}
{12={255=varchar($l)}, -3={255=tinyblob, 65535=blob, 16777215=mediumblob}, -1={65535=textt}}
==
hibernateTypeNames和originalColumnName都可以在CustomLoader中的getHibernateType看到
getHibernateType
Dialect类有两个属性
private final TypeNames typeNames = new TypeNames();
private final TypeNames hibernateTypeNames = new TypeNames();
报错会是:
typeNames No type mapping for java.sql.Types code
hibernateTypeNames No Hibernate type mapping for java.sql.Types code: