我有这种方法:
public List<Object[]> allIncomeChannels(final List<String> list) {
return entityManager.createQuery(
"select string_agg(a.logicalUnitIdent,',') idents, a.incomeChannel.code, a.logicalUnitIdent, a.keyword from IncomeChannelMapEntity a GROUP BY a.incomeChannel.code, a.logicalUnitCode,a.keyword",
Object[].class).getResultList();
}
但是我收到了错误消息:
org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌: 第1行,第44列附近的路标
任何建议我该如何解决?我正在使用postgres
答案 0 :(得分:1)
尝试对本地查询使用createNativeQuery()
方法。这是您更新的代码:
public List<Object[]> allIncomeChannels(final List<String> list) {
return entityManager.createNativeQuery(
"select string_agg(a.logicalUnitIdent,',') idents, a.incomeChannel.code, a.logicalUnitIdent, a.keyword from IncomeChannelMapEntity a GROUP BY a.incomeChannel.code, a.logicalUnitCode,a.keyword")
.getResultList();
}
在此处用本机查询替换查询。
答案 1 :(得分:0)
在您的查询中,string_agg(a.logicalUnitIdent,',')函数后缺少“ as”。就像这样
"select string_agg(a.logicalUnitIdent,',') as idents, a.incomeChannel.code,......"