Home > Database > Mysql Tutorial > No Dialect mapping for JDBC type:_MySQL

No Dialect mapping for JDBC type:_MySQL

WBOY
Release: 2016-06-01 13:18:42
Original
1176 people have browsed it

bitsCN.com

通过hql 语句没有问题,通过sql 就会有问题, 原因就是sql 在查找的字段中包含了mediumtext这类的字段类型,报错了,ejb 中 在sql 会报错。将其改成varchar类型就好了.

 

错误Exception:  
 org.hibernate.MappingException: No Dialect mapping for JDBC type: -1  
     at org.hibernate.dialect.TypeNames.get(TypeNames.java:56)  
     at org.hibernate.dialect.TypeNames.get(TypeNames.java:81) 


问题原因:数据库表中有text类型的字段,而Hibernate在native查询中没有注册这个字段,因此发生这个错误。 

解决方法 :写一个类、修改hibernate配置文件。 写一个Dialect的子类,这里我 extends MySQL5Dialect类:  
 package xxx.xxx;    //xxx.xxx自己根据情况来写  import java.sql.Types;  
 import org.hibernate.dialect.MySQL5Dialect;  
 public class DialectForInkfish extends MySQL5Dialect {  
     public DialectForInkfish() {  
         super();  
         registerHibernateType(Types.LONGVARCHAR, 65535, "text");  
     }  
 }  
修改Hibernate配置文件hibernate.cfg.xml,把 
org.hibernate.dialect.MySQL5Dialect  
修改为: 
com.ibm.crl.inkfish.config.DialectForInkfish  
hibernate ntext 问题: 
1.先用FrontEnd Plus反编译SQLServerDialect,发现SQLServerDialect继承SybaseDialect,继承 Dialect,Dialect中有registerHibernateType方法,再查看SybaseDialect构造中 registerColumnType没有注册ntext类型。
到了这一步就明朗了,原来是Hibernate的hibernate.cfg.xml中dialect没有注册ntext的类型。那好,自己注册一个吧。
2.定义MySQLServerDialect 

package com.accp.birdbbs.orm; import org.hibernate.dialect.SQLServerDialect;import java .sql.Types; import org.hibernate.Hibernate;public class MySQLServerDialect extends SQLServerDialect{ public MySQLServerDialect() {      super();      registerHibernateType(Types.LONGVARCHAR, Hibernate.TEXT.getName()); }}
Copy after login

3.在hibernate.cfg.xml中使用MySQLServerDialect 

  <property name="dialect">     com.accp.birdbbs.orm.MySQLServerDialect  </property>
Copy after login

 

再次运行程序,一切OK

原文链接:http://itlife365.com/blog/read.php/472.htm

bitsCN.com
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template