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 #2377: GROUP_CONCAT does NOT work in QueryDSL
Created: 2018-11-12T08:51:02Z
Hi there,
I am struggling to figure out how to use 'GROUP_CONCAT' in QueryDSL.
final QDataSourceSmallEliminate eliminate = QDataSourceSmallEliminate.dataSourceSmallEliminate;
		final QLattitudeVisitor lattitude = LattitudeVisitorServiceImpl.$;
//		Expressions.stringOperation(SQLOps.GROUP_CONCAT, lattitude.tagName)
		
		return QuerydslUtils.newQuery(entityManager).select(Projections.constructor(EliminateLattitude.class, 
				eliminate.id, 
				JPAExpressions.selectDistinct( SQLExpressions.groupConcat(lattitude.tagName)).from(lattitude).where(lattitude.urlCrc.eq(eliminate.urlCrc))))
			.from(eliminate)
			.fetch();

Exception:
org.springframework.dao.InvalidDataAccessApiUsageException: No pattern found for GROUP_CONCAT; nested exception is java.lang.IllegalArgumentException: No pattern found for GROUP_CONCAT

...

Caused by: java.lang.IllegalArgumentException: No pattern found for GROUP_CONCAT
	at com.querydsl.core.support.SerializerBase.visitOperation(SerializerBase.java:280)
	at com.querydsl.jpa.JPQLSerializer.visitOperation(JPQLSerializer.java:437)
	at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:231)
	at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:31)
	at com.querydsl.core.types.OperationImpl.accept(OperationImpl.java:83)
	at com.querydsl.core.support.SerializerBase.handle(SerializerBase.java:92)
	at com.querydsl.jpa.JPQLSerializer.serialize(JPQLSerializer.java:203)
	at com.querydsl.jpa.JPQLSerializer.visit(JPQLSerializer.java:358)
	at com.querydsl.jpa.JPQLSerializer.visit(JPQLSerializer.java:39)
	at com.querydsl.core.types.SubQueryExpressionImpl.accept(SubQueryExpressionImpl.java:57)
	at com.querydsl.core.support.FetchableSubQueryBase.accept(FetchableSubQueryBase.java:150)
	at com.querydsl.core.support.SerializerBase.handle(SerializerBase.java:92)
	at com.querydsl.core.support.SerializerBase.handle(SerializerBase.java:119)
	at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:225)
	at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:31)
	at com.querydsl.core.types.ConstructorExpression.accept(ConstructorExpression.java:112)
	at com.querydsl.core.support.SerializerBase.handle(SerializerBase.java:92)
	at com.querydsl.jpa.JPQLSerializer.serialize(JPQLSerializer.java:203)
	at com.querydsl.jpa.JPAQueryBase.serialize(JPAQueryBase.java:60)
	at com.querydsl.jpa.JPAQueryBase.serialize(JPAQueryBase.java:50)
	at com.querydsl.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:98)
	at com.querydsl.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:94)
	at com.querydsl.jpa.impl.AbstractJPAQuery.fetch(AbstractJPAQuery.java:201)
	at com.moraydata.general.secondary.repository.impl.DataSourceSmallEliminateRepositoryImpl.findObject(DataSourceSmallEliminateRepositoryImpl.java:98)
	at com.moraydata.general.secondary.repository.impl.DataSourceSmallEliminateRepositoryImpl$$FastClassBySpringCGLIB$$b42d875d.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)


QueryDSL 4.2.1 & JDK1.8 & Spring Boot2.0 & MySQL 5.7.
I read through the latest reference doc still cannot find the answer, so what should I do to make it work ?
Please help.
Thanks in advance.
@Shredder121

Closing comment (2020-05-28T15:21:08Z): 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 (see the example in the comment above).
Duplicate of #2020.