Repository: querydsl/querydsl

Issue #2020: Support for GROUP_CONCAT() in QueryDSL
Created: 2016-09-19T01:42:04Z
Hello,
I'm using maven with querydsl version 4.1.4 and MariaDB 10.1.14
MariaDB supports GROUP_CONCAT() function.
But when i use it in querydsl like below, it occurs exception.
Is there any solution?
StringExpression snsPostShortNameList = Expressions.stringTemplate("GROUP_CONCAT(DISTINCT {0})", snsPost.snsType);

JPAQuery<?> query = new JPAQuery<Void>(entityManager);

return query.select(Projections.constructor(ContentListDto.class,
                  snsPostShortNameList))
            .from(snsPost)
            .fetchResults();

HQL: select GROUP_CONCAT(DISTINCT snsPost.snsType)

from core.common.db.repository.entity.SnsPost snsPost

ERROR org.hibernate.hql.internal.ast.ErrorCounter - line 1:8: unexpected token: GROUP_CONCAT

ERROR org.hibernate.hql.internal.ast.ErrorCounter - line 1:8: unexpected token: GROUP_CONCAT

antlr.NoViableAltException: unexpected token: GROUP_CONCAT

    at org.hibernate.hql.internal.antlr.HqlBaseParser.identPrimaryBase(HqlBaseParser.java:4793)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.identPrimary(HqlBaseParser.java:4252)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:975)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.atom(HqlBaseParser.java:3530)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3383)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:3255)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2912)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:597)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2679)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2540)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2504)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2420)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2385)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.expression(HqlBaseParser.java:2098)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.aliasedExpression(HqlBaseParser.java:2339)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.selectedPropertiesList(HqlBaseParser.java:1372)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.selectClause(HqlBaseParser.java:1282)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1022)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:730)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:323)

    at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:186)

    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:279)

    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:187)

    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)

    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)

    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76)

    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150)

    at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302)

    at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240)

    at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1907)

    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:294)

    at com.sun.proxy.$Proxy96.createQuery(Unknown Source)

    at com.querydsl.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:101)

at com.querydsl.jpa.impl.AbstractJPAQuery.fetchResults(AbstractJPAQuery.java:215)
...

Duplicate issue #2192: how to use group_concat in queryDSL?
Created: 2017-08-26T02:22:16Z
i just to use querydsl in my project, there is my problerm that i don't know how to use group_concat in queryDSL,.

may someone help me ?  thanks!

Closing comment (2020-05-28T15:12:10Z): For SQL use SQLExpressions.groupConcat. For JPA this is not supported, because GROUP_CONCAT is not a function defined for JPQL. None of the ORM vendors ship it by default, although the function can be registered manually in some cases.
Duplicate of #2020.