本文介绍了谓词按位“&”运算符检查JPA2中的where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在SQl where子句中使用返回谓词的JPA2来为bitWise运算符'&'放置一个条件。
解决方案创建一个NamedQuery / NativeQuery
2.创建一个扩展org.hibernate.dialect.MySQLDialect的类MySQLDialect
2.创建一个扩展org.hibernate.dialect.MySQLDialect的类MySQLDialect
public class MySQLDialect extends org.hibernate.dialect.MySQLDialect {
public MySQLDialect(){
super();
registerFunction(bitwiseAnd,new SQLFunctionTemplate(StandardBasicTypes.BIG_INTEGER,
(?1&?2)));
}
3.确保你在你的hibernate.cfg中放置了下面的语句。 xml
com.Mypackage.MySQLDialect
TypedQuery< UserDefClass> q = em.createNamedQuery(Your NativeQuery name,UserDefClass.class);
q.setParameter(0,value);
q.setParameter(1,new BigInteger(value));
列表< UserDefClass> list = q.getResultList();
希望这可以帮助别人。我希望hibernate-JPA社区也为位运算符增加内置的帮助。 / p>
Is there a way to put a condition for bitWise operator '&' in SQl where clause, using JPA2 which returns a predicate.
解决方案
1.Create a NamedQuery/NativeQuery2.Create a class MySQLDialect which extends org.hibernate.dialect.MySQLDialect
public class MySQLDialect extends org.hibernate.dialect.MySQLDialect {
public MySQLDialect() {
super();
registerFunction("bitwiseAnd", new SQLFunctionTemplate(StandardBasicTypes.BIG_INTEGER,
"(?1 & ?2)"));
}
3.Make sure you place te below statement in your "hibernate.cfg.xml"
com.Mypackage.MySQLDialect
4.In your dao class you can call the above "bitwiseAnd" method like below
TypedQuery<UserDefClass> q = em.createNamedQuery("YOUR NativeQuery name", UserDefClass.class);
q.setParameter(0, value);
q.setParameter(1, new BigInteger(value));
List<UserDefClass> list = q.getResultList();
Hope this helps someone.I hope hibernate-JPA community adds inbuilt help for bitwise operators as well.
这篇关于谓词按位“&”运算符检查JPA2中的where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-21 17:28