【问题标题】:Case statement in Hibernate JPAHibernate JPA 中的案例语句
【发布时间】:2015-06-23 06:46:21
【问题描述】:

我收到以下错误,有人可以帮助我吗?

2015-04-16 12:17:26,330 ERROR [http-8080-Processor23] ErrorCounter - line 1:225: unexpected token: -
2015-04-16 12:17:26,345 ERROR [http-8080-Processor23] ErrorCounter - line 1:253: unexpected token: else
2015-04-16 12:17:26,345 ERROR [http-8080-Processor23] ErrorCounter - line 1:327: expecting CLOSE, found '.'

这是我的查询..

public List<DwnGactABForFile> getDwnGactABForFile(String sqlCrit)
            throws DataAccessException {        
        String sql = "select new com.compass.beactive.vo.DwnGactABForFile(a.gaaAccnum, a.gaaSrccode, a.gaaBuysellcode, b.gabScnetamt, a.gaaProcessdate," 
            + " (case when cast (a.gaaTransnetamt as float) = 0 then (cast(replace(a.gaaTransmarketvalue ,'-','0') as decimal(15,2))) else (cast(replace(a.gaaTransnetamt,'-','0') as decimal(15,2)))end)as a.gaaTransnetamt," 
            + " b.gabTradecurrcode, b.gabDescline01, b.gabDescline02, b.gabDescline03, "
            + " b.gabDescline04, b.gabDescline05, b.gabDescline06, b.gabDescline07, b.gabDescline08, b.gabDescline09, b.gabDescline10,"
            + " b.gabDescline11, b.gabDescline12) "
            + " from DwnGactA a, DwnGactB b "
            + " where a.gaaIdent = b.gabIdent "
            + " and a.gaaIdseqnum = b.gabIdseqnum "
            + sqlCrit
            + " order by a.gaaProcessdate ";
        Query query = this.entityManager.createQuery(sql);
        System.out.println("Full sql query" +sqlCrit);
        return query.getResultList();

【问题讨论】:

    标签: java sql sql-server hibernate jpa


    【解决方案1】:

    我认为replace() 不是有效的 JPQL 或 HQL 函数。如果您的 Hibernate 版本支持 JPA 2.1,您可以尝试使用 function() 函数调用本机 DB 函数。例如,这应该适用于 MS SQL Server:

    function("replace", a.gaaTransmarketvalue , '-', '0')
    

    【讨论】:

      【解决方案2】:

      这解决了上述问题

      COALESCE(NULLIF(a.gaaTransnetamt, '0.000'), a.gaaTransmarketvalue)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-13
        • 2012-12-20
        • 1970-01-01
        • 1970-01-01
        • 2011-06-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多