- 浏览: 314033 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (254)
- java (178)
- tomcat (6)
- 邮件 (1)
- smtp (1)
- Linux (2)
- 编码 (2)
- 导入工程 (1)
- Specification Level (1)
- hibernate (10)
- 字段类型 (1)
- 字段类型匹配 (1)
- 数据库 (3)
- sql (9)
- struts2 (8)
- 类型转换 (2)
- java,MyEclipse,SVN (1)
- Myecplise (4)
- 输入校验 (1)
- JFrame (2)
- Oracle (8)
- google (1)
- Swing (3)
- Fusioncharts (1)
- 找工作 (0)
- js (4)
- jsp (11)
- displaytag (1)
- spring (8)
- 工作 (1)
- String (1)
- 算法 (2)
- IO (1)
- xml (3)
- 设计模式 (1)
- UML (1)
- 文档 (1)
- ajax (1)
- 日常 (7)
- sql server (1)
- mysql (3)
- git (1)
- Maven (1)
- mongodb (1)
- postman (1)
最新评论
按位与运算(&)在许多数据库中都是支持的,遗憾的是,Hibernate 3在HQL中不支持&运算,如果你写了如下的HQL:
where a.id & :mask = :target
则Hibernate报错:exception: unexpected char: '&'.
如何解决此问题?方法是利用Hibernate支持的自定义SQLFunction,定义一个bitand(a,b)的SQLFunction,然后,自己写一个解释器,生成a & b的SQL语句。
要实现一个自定义的SQLFunction,必须实现SQLFunction接口:
package com.js.dialect;
import java.util.List;
import org.hibernate.QueryException;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
/**
* <p>
* Title:BitAndFunction
* </p>
* <p>
* Description:
* </p>
*
* @author js
* @version
* @since
*/
public class BitAndFunction implements SQLFunction {
public Type getReturnType(Type type, Mapping mapping) {
return StandardBasicTypes.INTEGER;
}
public boolean hasArguments() {
return true;
}
public boolean hasParenthesesIfNoArguments() {
return true;
}
@Override
public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor factory) throws QueryException {
if (arguments.size() != 2) {
throw new IllegalArgumentException("BitAndFunction requires 2 arguments!");
}
return arguments.get(0).toString() + " & " + arguments.get(1).toString();
}
}
然后,根据使用的数据库方言,派生一个自定义的CustomSQLDialect:
package com.js.dialect;
import org.hibernate.dialect.MySQLInnoDBDialect;
/**
* <p>
* Title:CustomSQLDialect
* </p>
* <p>
* Description:
* </p>
*
* @author js
* @version
* @since
*/
public class CustomSQLDialect extends MySQLInnoDBDialect {
/**
*
*/
public CustomSQLDialect() {
super();
registerFunction("bitand", new BitAndFunction());
}
}
设定函数名为bitand,参数和返回值均为Hibernate.LONG,现在,用CustomSQLDialect替换配置文件中的设置,
CustomSQLDialect 这个是注册自定义function用的,
在hibernate.xml 的prop里面配置。
例如<prop key="hibernate.dialect">com....CustomSQLDialect</prop>
中间换成你的路径
然后修改HQL:
where bitand(a.id, :mask) = :target
注:转自 http://hi.baidu.com/sushangzhou/blog/item/0f743bfa5a2ffb1f6d22eb9d.html
在配置hibernate.cfg.xml时需指定使用数据库的方言:
例:
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
以下是各数据库对应的方言(Dialect):
数据库
方言(Dialect)
DB2
org.hibernate.dialect.DB2Dialect
DB2 AS/400
org.hibernate.dialect.DB2400Dialect
DB2 OS390
org.hibernate.dialect.DB2390Dialect
PostgreSQL
org.hibernate.dialect.PostgreSQLDialect
MySQL5
org.hibernate.dialect.MySQL5Dialect
MySQL5 with InnoDB
org.hibernate.dialect.MySQL5InnoDBDialect
MySQL with MyISAM
org.hibernate.dialect.MySQLMyISAMDialect
Oracle(any version)
org.hibernate.dialect.OracleDialect
Oracle 9i
org.hibernate.dialect.Oracle9iDialect
Oracle 10g
org.hibernate.dialect.Oracle10gDialect
Oracle 11g
org.hibernate.dialect.Oracle10gDialect
Sybase
org.hibernate.dialect.SybaseASE15Dialect
Sybase Anywhere
org.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Server 2000
org.hibernate.dialect.SQLServerDialect
Microsoft SQL Server 2005
org.hibernate.dialect.SQLServer2005Dialect
Microsoft SQL Server 2008
org.hibernate.dialect.SQLServer2008Dialect
SAP DB
org.hibernate.dialect.SAPDBDialect
Informix
org.hibernate.dialect.InformixDialect
HypersonicSQL
org.hibernate.dialect.HSQLDialect
H2 Database
org.hibernate.dialect.H2Dialect
Ingres
org.hibernate.dialect.IngresDialect
Progress
org.hibernate.dialect.ProgressDialect
Mckoi SQL
org.hibernate.dialect.MckoiDialect
Interbase
org.hibernate.dialect.InterbaseDialect
Pointbase
org.hibernate.dialect.PointbaseDialect
FrontBase
org.hibernate.dialect.FrontbaseDialect
Firebird
org.hibernate.dialect.FirebirdDialect
转载请注明出处:http://blog.csdn.net/jialinqiang/article/details/8679171
where a.id & :mask = :target
则Hibernate报错:exception: unexpected char: '&'.
如何解决此问题?方法是利用Hibernate支持的自定义SQLFunction,定义一个bitand(a,b)的SQLFunction,然后,自己写一个解释器,生成a & b的SQL语句。
要实现一个自定义的SQLFunction,必须实现SQLFunction接口:
package com.js.dialect;
import java.util.List;
import org.hibernate.QueryException;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
/**
* <p>
* Title:BitAndFunction
* </p>
* <p>
* Description:
* </p>
*
* @author js
* @version
* @since
*/
public class BitAndFunction implements SQLFunction {
public Type getReturnType(Type type, Mapping mapping) {
return StandardBasicTypes.INTEGER;
}
public boolean hasArguments() {
return true;
}
public boolean hasParenthesesIfNoArguments() {
return true;
}
@Override
public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor factory) throws QueryException {
if (arguments.size() != 2) {
throw new IllegalArgumentException("BitAndFunction requires 2 arguments!");
}
return arguments.get(0).toString() + " & " + arguments.get(1).toString();
}
}
然后,根据使用的数据库方言,派生一个自定义的CustomSQLDialect:
package com.js.dialect;
import org.hibernate.dialect.MySQLInnoDBDialect;
/**
* <p>
* Title:CustomSQLDialect
* </p>
* <p>
* Description:
* </p>
*
* @author js
* @version
* @since
*/
public class CustomSQLDialect extends MySQLInnoDBDialect {
/**
*
*/
public CustomSQLDialect() {
super();
registerFunction("bitand", new BitAndFunction());
}
}
设定函数名为bitand,参数和返回值均为Hibernate.LONG,现在,用CustomSQLDialect替换配置文件中的设置,
CustomSQLDialect 这个是注册自定义function用的,
在hibernate.xml 的prop里面配置。
例如<prop key="hibernate.dialect">com....CustomSQLDialect</prop>
中间换成你的路径
然后修改HQL:
where bitand(a.id, :mask) = :target
注:转自 http://hi.baidu.com/sushangzhou/blog/item/0f743bfa5a2ffb1f6d22eb9d.html
在配置hibernate.cfg.xml时需指定使用数据库的方言:
例:
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
以下是各数据库对应的方言(Dialect):
数据库
方言(Dialect)
DB2
org.hibernate.dialect.DB2Dialect
DB2 AS/400
org.hibernate.dialect.DB2400Dialect
DB2 OS390
org.hibernate.dialect.DB2390Dialect
PostgreSQL
org.hibernate.dialect.PostgreSQLDialect
MySQL5
org.hibernate.dialect.MySQL5Dialect
MySQL5 with InnoDB
org.hibernate.dialect.MySQL5InnoDBDialect
MySQL with MyISAM
org.hibernate.dialect.MySQLMyISAMDialect
Oracle(any version)
org.hibernate.dialect.OracleDialect
Oracle 9i
org.hibernate.dialect.Oracle9iDialect
Oracle 10g
org.hibernate.dialect.Oracle10gDialect
Oracle 11g
org.hibernate.dialect.Oracle10gDialect
Sybase
org.hibernate.dialect.SybaseASE15Dialect
Sybase Anywhere
org.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Server 2000
org.hibernate.dialect.SQLServerDialect
Microsoft SQL Server 2005
org.hibernate.dialect.SQLServer2005Dialect
Microsoft SQL Server 2008
org.hibernate.dialect.SQLServer2008Dialect
SAP DB
org.hibernate.dialect.SAPDBDialect
Informix
org.hibernate.dialect.InformixDialect
HypersonicSQL
org.hibernate.dialect.HSQLDialect
H2 Database
org.hibernate.dialect.H2Dialect
Ingres
org.hibernate.dialect.IngresDialect
Progress
org.hibernate.dialect.ProgressDialect
Mckoi SQL
org.hibernate.dialect.MckoiDialect
Interbase
org.hibernate.dialect.InterbaseDialect
Pointbase
org.hibernate.dialect.PointbaseDialect
FrontBase
org.hibernate.dialect.FrontbaseDialect
Firebird
org.hibernate.dialect.FirebirdDialect
转载请注明出处:http://blog.csdn.net/jialinqiang/article/details/8679171
发表评论
-
领域精通涉及技术点(不分先后)
2017-12-20 19:35 561Java8 netty jvm kafaka消息队列 上传下载 ... -
计算机各种单位讲解及换算
2017-12-13 13:54 1541我还听过有UK的 一、最小单位:位(bit,缩写为b) 在原 ... -
JAVA字符串格式化-String.format()和MessageFormat的使用
2017-12-05 10:39 1277String.format()常规类型的格式化 Stri ... -
eclipse启动项目常见问题
2017-11-16 17:46 1138今儿遇到了个问题,ecli ... -
字符编码笔记:ASCII,Unicode和UTF-8
2017-10-23 16:37 417讲的太牛逼了: http://ww ... -
emoji简单讲解
2017-10-23 15:17 913emoji处理方式大起底 http://blog.csdn.n ... -
BigDecimal讲解
2017-10-12 15:58 399BigDecimal 由任意精度的整数非标度值 和 32 位的 ... -
eclips 控制台console上不打印信息
2017-09-06 21:53 5351、进windows菜单 -> show view -& ... -
详解RequestMappingHandlerMapping和RequestMappingHandlerAdapter
2017-08-29 17:08 2908http://donald-draper.iteye.com/ ... -
用@ExceptionHandler 来进行切面异常处理
2017-08-29 11:47 2223有时候我们想处理某个类里Controller中抛出的异常怎么搞 ... -
Spring 注解@Component、@Repository、@Service、@Controller区别
2017-08-28 15:27 961spring 2.5 中除了提供 @Com ... -
线程的一点小总结
2017-08-23 20:36 658java中main方法启动的是一个进程还是一个线程? 答:是一 ... -
线程池
2017-08-23 17:35 474诸如Web 服务器、数据库 ... -
Class源码大概讲解
2017-08-23 16:47 474http://blog.csdn.net/a327369238 ... -
Spring 事务相关
2017-08-14 12:10 434Transactionz注解的readOnly ... -
把时间当做朋友-前言
2017-08-13 20:47 363要管理的不是时间,而是自己。人们生活在同一个世界,却又各自 ... -
单例里面的方法讲解
2017-08-11 14:55 454spring里的controller是单例的。系统针对每个co ... -
eclipse拷贝出来的项目名称还是原来的
2017-07-26 16:46 1027需要修改的有如下几个地方: 1、pom.xml里面打包的名字一 ... -
http请求参数:header body paramter三种参数区别、联系
2017-06-19 10:46 477012345 -
spring依赖包解析
2017-06-01 14:36 335http://www.cnblogs.com/leehonge ...
相关推荐
达梦数据库各版本的hibernate方言包,包含版本 DmDialect-for-hibernate2.0、DmDialect-for-hibernate2.1、DmDialect-for-hibernate3.0、DmDialect-for-hibernate3.1、DmDialect-for-hibernate3.6、DmDialect-for-...
* 达梦8 hibernate方言包对应版本说明 /*************************************** jar包在dialect目录下: 1. DmDialect-for-hibernate2.0.jar 对应 Jdk1.4及以上, hibernate2.0 环境 2. DmDialect-for-hibernate2.1...
hibernate方言包
达梦Hibernate方言2.0至4.0
hibernate 方言 支持access
sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言
达梦Hibernate方言2.0至4.0,当工具书用的.最新方言还是要参考用户手册.方言覆盖的数据库越来越多了
hibernate支持的所有数据库方言。用起来很方便。
eclipse下使用hibernate tools实现hibernate逆向工程时 生成实体类时可以自动添加数据库中的注释
Hibernate Validator 是 Bean ... Hibernate Validator 提供了 JSR 303 规范中所有内置 constraint 的实现,下面这篇文章主要给大家介绍了关于如何自定义hibernate validation注解的相关资料,需要的朋友可以参考下
NULL 博文链接:https://jadeluo.iteye.com/blog/1213549
瀚高数据库hibernate方言 hgdb-hibernate-dialect
hibernate自定义查询
struts+hibernate+自定义标签 做的分页模板
达梦数据库7.6最新的驱动包及hibernate方言包,含JDK1.5到JDK1.8驱动包和haibernate 5.3及一下方言包
hibernate方言汇总.docx和SSH的jar包名称