Hibernate Regexp MySQL [英] Hibernate Regexp MySQL
问题描述
问题:
SELECT * FROM table WHERE regexp column'\d'
解决方案:
转到我的答案。
希望这有助于您。
基本上,要在Hibernate中使用MySQL regexp函数,我们需要创建一个SQLFunctionTemplate。
<首先:创建一个名为AppMySQLDialect的类,并从MySQLDialect继承,然后覆盖空的构造函数,最后注册regexp函数:
现在,如何做到这一点: / p>
public class AppMySQLDialect extends MySQLDialect {
public AppMySQLDialect(){
super();
/ **
*用于评估MySQL中的正则表达式的函数
* /
registerFunction(regexp,new SQLFunctionTemplate(Hibernate.INTEGER,?1 REGEXP?2)) ;
$ / code $ / pre
好的,现在让我们按照下面的方式使用它: p>
FROM实体E WHERE regexp(E.string2evaluate,'\ d')= 1
创建您的HibernateQuery并执行。
I ask this question to show how MySQL and Hibernate work each other with Regular Expressions.
The problem:
SELECT * FROM table WHERE regexp column '\d'
Solution:
Go to my answer.
Hope this helps.
解决方案 Basically, to use MySQL regexp function in Hibernate we need to create a "SQLFunctionTemplate".
Now, how to do it:
First: Create a class called "AppMySQLDialect" and extends from MySQLDialect then override the empty constructor and finally register the regexp function:
public class AppMySQLDialect extends MySQLDialect {
public AppMySQLDialect() {
super();
/**
* Function to evaluate regexp in MySQL
*/
registerFunction("regexp", new SQLFunctionTemplate(Hibernate.INTEGER, "?1 REGEXP ?2"));
}
}
Ok, now lets use it as follow:
FROM Entity E WHERE regexp(E.string2evaluate, '\d') = 1
Create your HibernateQuery and execute.
这篇关于Hibernate Regexp MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!