简体   繁体   English

如何为查询创建标准休眠状态(len(),PATINDEX(),replace)

[英]How create criteria hibernate for query(len(), PATINDEX(),replace)

I have hql query: 我有hql查询:

... WHERE len(p.sms.message) - len(replace(p.sms.message,:message1,'')) = 1 AND PATINDEX('%[0-9]%',replace(p.sms.message,:message1,'')) = 0"

I need alter the criteria hibernate like: 我需要更改休眠的条件,例如:

criteria.add(Restrictions.eq("field", field));

How do it? 怎么了

OR i jast need check string by regex ^[^0-9]*[0][^0-9]*$ but I use MSSQL. 或者我只是需要用正则表达式^[^0-9]*[0][^0-9]*$检查字符串,但是我使用MSSQL。 Can I do it in hibernate? 我可以休眠吗?

You can use sqlRestriction 您可以使用sqlRestriction

criteria.add(Restrictions.sqlRestriction(...));

Any occurrences of {alias} will be replaced by the table alias. 任何出现的{alias}都将被表别名替换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM