读书人

mysql数据库遇到:org.hibernate.Mapp

发布时间: 2013-03-01 18:33:02 作者: rapoo

mysql数据库遇到:org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
在做web项目时,用到了mysql数据库和ssh架构,登录系统后,做查询时候,查询出来的list应该为null,但结果却报下面的错误:
org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
分析原因:hibernate无法将指定的数据库类型转换为java中的类型而导致的错误。
解决方法:自定义一个mysql方言,并加入这个长varchar类型的定义即可解决问题。
步骤如下:
1,定义一个java类,代码如下:

package com.sense.workflow.util;import java.sql.Types;import org.hibernate.Hibernate;import org.hibernate.dialect.MySQL5Dialect;/** * mysql注册类型映射 * @author Kevin12 * */public class ExtMySQL5Dialect  extends MySQL5Dialect{public ExtMySQL5Dialect(){super();this.registerHibernateType(Types.LONGVARCHAR, Hibernate.STRING.getName());}}

2,修改hibernate的配置文件:
原配置文件代码(部分代码):
       <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/myworkflow?characterEcoding/=utf-8</property><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.connection.username">root</property><property name="hibernate.connection.password">root</property><property name="hibernate.dialect">[color=red]org.hibernate.dialect.MySQLInnoDBDialect[/color]</property><property name="hibernate.hbm2ddl.auto">update</property><property name="hibernate.show_sql">true</property>

修改后的代码:
       <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/myworkflow?characterEcoding/=utf-8</property><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.connection.username">root</property><property name="hibernate.connection.password">root</property><property name="hibernate.dialect"><!-- org.hibernate.dialect.MySQLInnoDBDialect -->[color=red][b]com.sense.workflow.util.ExtMySQL5Dialect[/b][/color]</property><property name="hibernate.hbm2ddl.auto">update</property><property name="hibernate.show_sql">true</property>

读书人网 >其他数据库

热点推荐