0

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

2
  • Please edit your question to include the database system you are using. Commented Aug 29, 2019 at 18:39
  • im using postgres Commented Aug 29, 2019 at 18:39

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

when im using this query im getting error : No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode \r\n +-[METHOD_CALL] MethodNode........
i dont know why but now im getting this error : ERROR: relation "incomechannelmapentity" does not exist
What is your table name?
table is call r_income_channel_map , but enttiy in java is IncomeChannelMapEntity
|
0

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,......"

3 Comments

if i use as im getting another error : No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode
I believe you are using HQL and IncomeChannelMapEntity is your Java object. Is 'idents' field available in your java object?
i dont have that filed, its alias

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.