Reputation: 9247
I have this method:
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();
}
But im getting error :
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: idents near line 1, column 44
Any suggestion how can i fix this? Im using postgres
Upvotes: 0
Views: 2583
Reputation: 3866
Try using createNativeQuery()
method with a native query. Here is your updated code:
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();
}
Replace the query with a native query here.
Upvotes: 1
Reputation: 943
In your query 'as' is missing after string_agg(a.logicalUnitIdent,',') function. It would be like this
"select string_agg(a.logicalUnitIdent,',') as idents, a.incomeChannel.code,......"
Upvotes: 0