【问题标题】:Call Oracle's native function (wm_concat) through query dsl通过查询dsl调用Oracle的原生函数(wm_concat)
【发布时间】:2015-01-14 04:38:11
【问题描述】:

我的问题是不知道如何通过q​​uery dsl正确调用Oracle的原生函数。

我的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.IllegalStateException:节点没有数据类型:org.hibernate.hql.internal.ast.tree.MethodNode -[METHOD_CALL] MethodNode:'函数(wm_concat)' +-[METHOD_NAME] IdentNode: 'wm_concat' {originalText=wm_concat}

我正在使用带有休眠功能的 JPA 2.1

问候

【问题讨论】:

    标签: querydsl jpa-2.1


    【解决方案1】:

    以下代码适用于我。

    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。

    我唯一做的就是替换 StringTemplate.create() 函数 通过 Expressions.stringTemplate() 函数。

    为了完整起见,我在 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;
    

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      相关资源
      最近更新 更多