如何使用CriteriaBuilder调用db函数

时间:2018-10-02 15:15:45

标签: java hibernate hibernate-criteria

我有一个可能最终包含空格的字符串。我想用与\ t,\ r,\ n匹配的正则表达式替换那些空格。替换后,我想调用regexp_like(一个oracle函数)以将字段与该字符串进行匹配。

我知道可以使用this link

中所述的条件构建器来调用db函数。

我不是很熟悉Java与oracle之间的正则表达式之间的区别,也不是如何将它们拼凑在一起的(我从未从criteriabuilder调用过函数)。这是我在评论中卡住的地方的初步步骤

// first replace all spaces with regex for \s,\r,\t, value is the original string
value.replaceAll(" +", "[\\t\\n\\r]+")
// build the db function call expression, seems I cant do table.<String>get(field) and cant pass value as a string
Expression<String> regExp = cb.function("regexp_like", String.class, table.<String>get(field), value);
// now create a predicate not sure how
Predicate fieldMatch = cb.equal(...)

这可能吗?

0 个答案:

没有答案