2014-11-17 80 views
3

調用Oracle的本地函數(wm_concat)我的問題是我不知道如何通過查詢dsl正確調用Oracle的本地函數。通過查詢dsl

我的SQL查詢

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

我查詢DSL版本

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)); 

生成jqpl是:

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

我得到下面的異常

的Java。 lang.Ille galStateException:節點沒有數據類型:org.hibernate.hql.internal.ast.tree.MethodNode - [METHOD_CALL] MethodNode:'function(wm_concat)' + - [METHOD_NAME] IdentNode:'wm_concat'{originalText = wm_concat}

我使用JPA 2.1和Hibernate

問候

回答

0

下面的代碼對我的作品。

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

我使用QueryDsl版本3.7.2。

我做的唯一事情就是用Expressions.stringTemplate()函數替換StringTemplate.create()函數 。

爲了完整起見,我在Java代碼開始時定義了所有以下QueryDsl導入。

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;