我正在从 Hibernate Criteria API 升级到 JPA2 Criteria API,并且遇到了以下问题,我似乎无法解决。
在 Hibernate Criteria 中,我使用 Restrictions.sqlRestriction 检查特定类型的字符串子集:
criteria.add(Restrictions.sqlRestriction("{alias}.location_key = left((?), length({alias}.location_key))", searchObj.getLocationKey(), Hibernate.STRING));
这实质上检查N
输入字符串的第一个字母是否与N
字母长的 location_key 匹配。那就是输入字符串Canada,ON
应该与类似的东西匹配:Canada
或Can
或C
。
The problem is that JPA2 doesn't allow us to code native sql like that, and I'm not sure how I can achieve something similar without the left
function (which I think might be mysql specific).
Any help is appreciated!