Call Oracle's native function (wm_concat) through query dsl

1.6k Views Asked by At

My problem is that I don't know how to call correctly Oracle's native function through query dsl.

My sql query is

select  wm_concat(COU_NAME) 
from COUNTRIES
where COU_COUNTRY_ID_PK in (1,2)

My query dsl version is

JPAQuery query = new JPAQuery(entityManager); 
List<String> test = query.from(qCountr3).where(qCountr3.id.in(1L,2L)).list(StringTemplate.create("function('wm_concat',{0})",qCountr3.name));

Generated jqpl is:

select function('wm_concat',qCountry3.name)
from Country qCountry3
where qCountry3.id in (?1)

And I get the following exception

java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode -[METHOD_CALL] MethodNode: 'function (wm_concat)' +-[METHOD_NAME] IdentNode: 'wm_concat' {originalText=wm_concat}

I'm using JPA 2.1 with hibernate

Regards

1

There are 1 best solutions below

0
On

The following code works for me.

List<String> list 
  = query
    .from(qCountr3)
    .where(qCountr3.id.in(1L,2L))
    .list(Expressions
             .stringTemplate
                ("function('WM_CONCAT',{0})"
                ,qCountr3.name
                )
         );

I use QueryDsl version 3.7.2.

The only thing I have done is replacing StringTemplate.create() function by Expressions.stringTemplate() function.

To be complete, I have defined all following QueryDsl import at begin of my Java code.

import com.mysema.query.jpa.impl.JPAQuery;
import com.mysema.query.jpa.sql.JPASQLQuery;
import com.mysema.query.sql.OracleTemplates;
import com.mysema.query.sql.SQLTemplates;
import com.mysema.query.support.Expressions;
import com.mysema.query.types.expr.BooleanExpression;
import com.mysema.query.types.path.StringPath;