首页 > 代码库 > No Dialect mapping for JDBC type: -9

No Dialect mapping for JDBC type: -9

由于项目中使用的是hibernate 4.35版本和sqlserver 2008数据库。所以,自定义方言时,需要和老版本做区别:

public class MySQLServerDialect extends SQLServerDialect { public MySQLServerDialect() {     super();     registerHibernateType(1, "string");          registerHibernateType(-9, "string");          registerHibernateType(-16, "string");          registerHibernateType(3, "double");              registerHibernateType(Types.CHAR, StandardBasicTypes.STRING.getName());          registerHibernateType(Types.NVARCHAR, StandardBasicTypes.STRING.getName());          registerHibernateType(Types.LONGNVARCHAR, StandardBasicTypes.STRING.getName());          registerHibernateType(Types.DECIMAL, StandardBasicTypes.DOUBLE.getName()); }}

然后注意修改hibernate 配置。本项目是将hibernate托管于spring,

  <property name="hibernateProperties">  <props>   <prop key="hibernate.show_sql">true</prop>   <prop key="current_session_context_class">thread</prop>  <!--   <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> -->  <prop key="hibernate.dialect">manage.myextends.sqlserver.MySQLServerDialect</prop>   </props>  </property>

 

No Dialect mapping for JDBC type: -9