Hibernate SQL QUERY,与mysql中的TEXT数据类型有关 [英] Hibernate SQL QUERY, problem with TEXT data type in mysql

查看:116
本文介绍了Hibernate SQL QUERY,与mysql中的TEXT数据类型有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  org.hibernate.MappingException:无JDBC类型的方言映射:-1 

我不知道该怎么做,映射不是一个选项(数据库中的动态表,所以字段数是可变的)。



以下是一段代码:

  SQLQuery query = session。 createSQLQuery(SQL); 

Object [] values =(Object [])query.uniqueResult();

sql是一个包含查询的字符串(它可以与mysql查询引擎正常运行)。如果我将TEXT数据类型更改为varchar,工作正常,但这也不是一种选择!



任何线索?

  package iam.dirty; 
import java.sql.Types;

导入org.hibernate.Hibernate;
导入org.hibernate.dialect.SQLServerDialect;

public class DialectForGkoloc extends SQLServerDialect {
public DialectForGkoloc(){
super();

registerHibernateType(Types.DECIMAL,Hibernate.BIG_DECIMAL.getName());
registerHibernateType(-1,Hibernate.STRING.getName());
registerHibernateType(Types.LONGVARCHAR,Hibernate.TEXT.getName());
}

}

修改Hibernate配置文件hibernate。 cfg.xml:

 < property name =dialect> 
org.hibernate.dialect.SQLServerDialect
< / property>

附带:

 < property name =dialect> 
iam.dirty.DialectForGkoloc
< / property>


I need to perform a sql query with hibernate ( no mapping ) but i keep getting this error whenever a field has a TEXT data type in MYSQL :

org.hibernate.MappingException: No Dialect mapping for JDBC type: -1

I don't know what to do, mapping is not an option ( dynamic tables in the database , so the number of fields is variable ).

Here's the piece of code :

SQLQuery query = session.createSQLQuery(sql);

Object[] values = (Object[]) query.uniqueResult();

sql is a String containing the query ( it runs ok with mysql query engine ). If I change the TEXT data type to varchar, works fine, but that's not an option neither !

Any clues ?

解决方案

Here's a possible solution:

package iam.dirty;
import java.sql.Types;

import org.hibernate.Hibernate;
import org.hibernate.dialect.SQLServerDialect;

public class DialectForGkoloc extends SQLServerDialect {
     public DialectForGkoloc() {
        super();

        registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName());   
        registerHibernateType(-1, Hibernate.STRING.getName());
        registerHibernateType(Types.LONGVARCHAR, Hibernate.TEXT.getName());
     }

}

Modify the Hibernate configuration file hibernate.cfg.xml:

<property name="dialect"> 
 org.hibernate.dialect.SQLServerDialect 
</property>

with:

<property name="dialect"> 
 iam.dirty.DialectForGkoloc 
</property>

这篇关于Hibernate SQL QUERY,与mysql中的TEXT数据类型有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆