Calling Oracle native function (wm_concat) via dsl request

My problem is I don't know how to properly call an Oracle function using a dsl query.

My sql query

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

      

My dsl query version

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:

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

      

And I am getting the following exception

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

I am using JPA 2.1 with hibernate

Hello

+3


source to share


1 answer


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 am using QueryDsl version 3.7.2.



The only thing I did was replace the StringTemplate.create () function with the Expressions.stringTemplate () function.

To be complete, I have defined all of the following QueryDsl imports at the beginning 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;

      

0


source







All Articles