hibernate mysql自定义变量_hibernate如何得到mysql的变量

你这执行的是纯sql,貌似有的hibernate版本不能直接用sql操作mysql数据库,我猜你没在别的方法里用SQLQuery,如果其他地方可以执行那我给你的办法你就不用看了。我当时遇到过hibernate不能用SQLQuery操作mysql。

解决办法:你的hibernate配置文件里一定有个地方配置方言的如:

org.hibernate.dialect.MySQLDialect

你需要将MySQLDialect.java重写,我当时感觉改变它的jar里的文件比较麻烦,就直接重写的,实际就里面增加了两句,具体忘了。

源码:

package com.isd.dig.util;

/*jadclipse*/// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.

import java.sql.CallableStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import org.hibernate.Hibernate;

import org.hibernate.dialect.Dialect;

import org.hibernate.dialect.function.NoArgSQLFunction;

import org.hibernate.dialect.function.StandardSQLFunction;

import org.hibernate.util.StringHelper;

// Referenced classes of package org.hibernate.dialect:

//            Dialect

//解决hibernate的Dialect问题,使操作MYSQL数据库时候 sql可以使用  createSQLQuery方法查询*andy*

public class MySQLDialect extends Dialect

{

public MySQLDialect()

{

registerColumnType(-7, "bit");

registerColumnType(-5, "bigint");

registerColumnType(5, "smallint");

registerColumnType(-6, "tinyint");

registerColumnType(4, "integer");

registerColumnType(1, "char(1)");

registerColumnType(6, "float");

registerColumnType(8, "double precision");

registerColumnType(91, "date");

registerColumnType(92, "time");

registerColumnType(93, "datetime");

registerColumnType(-3, "longblob");

registerColumnType(-3, 16777215, "mediumblob");

registerColumnType(-3, 65535, "blob");

registerColumnType(-3, 255, "tinyblob");

registerColumnType(2, "numeric($p,$s)");

registerColumnType(2004, "longblob");

registerColumnType(2004, 16777215, "mediumblob");

registerColumnType(2004, 65535, "blob");

registerColumnType(2005, "longtext");

registerColumnType(2005, 16777215, "mediumtext");

registerColumnType(2005, 65535, "text");

registerVarcharTypes();

registerFunction("ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER));

registerFunction("bin", new StandardSQLFunction("bin", Hibernate.STRING));

registerFunction("char_length", new StandardSQLFunction("char_length", Hibernate.LONG));

registerFunction("character_length", new StandardSQLFunction("character_length", Hibernate.LONG));

registerFunction("lcase", new StandardSQLFunction("lcase"));

registerFunction("lower", new StandardSQLFunction("lower"));

registerFunction("length", new StandardSQLFunction("length", Hibernate.LONG));

registerFunction("ltrim", new StandardSQLFunction("ltrim"));

registerFunction("ord", new StandardSQLFunction("ord", Hibernate.INTEGER));

registerFunction("quote", new StandardSQLFunction("quote"));

registerFunction("reverse", new StandardSQLFun

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值