正则表达式在Hibernate中的查询 [英] Regex query in Hibernate

查看:238
本文介绍了正则表达式在Hibernate中的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Hibernate中实现以下查询的效果,但是我无法想出办法做到这一点。

I want to achieve the effect of following query in Hibernate, but I'm unable to figure out a way to do this.

select e.TITLE from EVENTS e where e.TITLE REGEXP 'fri|pro';

有人可以帮忙吗?

Can someone help?

推荐答案

Hibernate QL不支持正则表达式(并且某些引擎对正则表达式的支持很差)。
您可以将您的查询转换为

Hibernate QL doesn't support regular expressions (and some engines have a very poor regexes support). You can transform your query to be

select e.TITLE from EVENTS e where (e.TITLE = 'fri' OR e.TITLE = 'pro');

select e.TITLE from EVENTS e where e.TITLE in ('fri','pro');

但是对于 real 正则表达式支持,您必须编写自定义SQL如果你的数据库确实支持正则表达式)

But for real regex support you'll have to write custom SQL (if your DB does support regexes at all)

这篇关于正则表达式在Hibernate中的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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