我正在尝试创建一个 Java 命名查询,它执行以下 postgres 查询:
select * from call_attempt where result is NULL and id like '0000000101%';
我的代码中将 0000000101 设置为 id,所以这就是我想要做的,但格式不正确:(我不确定如何在使用 % 时设置 id 字段,它必须在 ' ' )
@NamedQuery(name = AttemptEntity.JQL.NOTENDED,
query = "SELECT ae FROM AttemptEntity ae WHERE ae.result IS NULL,"
+ " ae.correlationId LIKE '=:id%'")
最佳答案
首先,您忘记了和
,并用逗号代替了它。
其次,%
必须作为参数的一部分传递:
SELECT ae FROM AttemptEntity ae WHERE ae.result IS NULL
and ae.correlationId LIKE :id
然后,在执行查询时:
String id = "0000000101%";
query.setParameter("id", id);
关于Java 命名查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44185092/