将SQL翻译为CriteriaBuilder。

huangapple go评论77阅读模式
英文:

translate sql to criteriaBuilder

问题

select * 
from db_object o 
where o.value not like all (array ['%'||chr(32)||chr(32)||'%', '%'||chr(9)||'%', '%'||chr(10)||'%', '%'||chr(13)||'%'])

大家好,我不知道如何在CriteriaBuilder中更改SQL查询。我在这一行卡住了:

where o.value not like all (array ['%'||chr(32)||chr(32)||'%''%'||chr(9)||'%''%'||chr(10)||'%''%'||chr(13)||'%'])

非常感谢您的帮助,或者至少给出有趣资料的链接。
英文:
select * 
from db_object o 
where o.value not like all (array ['%'||chr(32)||chr(32)||'%', '%'||chr(9)||'%', '%'||chr(10)||'%', '%'||chr(13)||'%'])

Hello everyone, i dont now how to change sql request in CriteriaBuilder. I am stuck on this line:

where o.value not like all (array ['%'||chr(32)||chr(32)||'%', '%'||chr(9)||'%', '%'||chr(10)||'%', '%'||chr(13)||'%'])

I will be very grateful for your help or at least links to interesting material.

答案1

得分: 0

maybe to someone helps

CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<BaseObject> criteria = builder.createQuery(BaseObject.class);
Root<BaseObject> rootCriteria = criteria.from(BaseObject.class);
List<Predicate> criteriaList = new ArrayList<>();
criteriaList.add(builder.like(rootCriteria.get("value"), "%  %"));
criteriaList.add(builder.like(rootCriteria.get("value"), "%\n%"));
criteriaList.add(builder.like(rootCriteria.get("value"), "%\t%"));
criteriaList.add(builder.like(rootCriteria.get("value"), "%\r%"));
criteria.select(rootCriteria).where(
        builder.or(criteriaList.toArray(new Predicate[criteriaList.size()]))
    ).orderBy(builder.asc(rootCriteria.get("objectId")));
英文:

maybe to someone helps

CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery&lt;BaseObject&gt; criteria = builder.createQuery(BaseObject.class);
Root&lt;BaseObject&gt; rootCriteria = criteria.from(BaseObject.class);
List&lt;Predicate&gt; criteriaList = new ArrayList&lt;&gt;();
criteriaList.add(builder.like(rootCriteria.get(&quot;value&quot;), &quot;%  %&quot;));
criteriaList.add(builder.like(rootCriteria.get(&quot;value&quot;), &quot;%\n%&quot;));
criteriaList.add(builder.like(rootCriteria.get(&quot;value&quot;), &quot;%\t%&quot;));
criteriaList.add(builder.like(rootCriteria.get(&quot;value&quot;), &quot;%\r%&quot;));
criteria.select(rootCriteria).where(
        builder.or(criteriaList.toArray(new Predicate[criteriaList.size()]))
).orderBy(builder.asc(rootCriteria.get(&quot;objectId&quot;)));

huangapple
  • 本文由 发表于 2020年4月10日 21:17:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/61141107.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定