日期:2014-05-17  浏览次数:20918 次

hibernate使用case when 语句报错
以下是我的SQL,在PL/SQL中运行的没问题:
SQL code
select distinct pp.projectNo, pp.projectName, pp.applyNo
  from PrpSprojectMain pp
 where pp.projectNo in
       (select distinct case
                          when ms.subjectType = 'C' then
                           (select distinct p.projectNo
                              from PrpSprojectMain p
                             where p.applyNo = ms.businessNo)
                          when ms.subjectType = 'R' then
                           (select distinct p.projectNo
                              from PrpSprojectMain p
                             where p.projectNo in
                                   (select re.projectNo
                                      from PrpSprojectRenew re
                                     where re.renewNo = ms.businessNo))
                          when ms.subjectType = 'E' then
                           (select distinct p.projectNo
                              from PrpSprojectMain p
                             where p.applyNo in
                                   (select en.applyNo
                                      from PrpSprojectEndorMain en
                                     where en.endorNo = ms.businessNo))
                        end
          from MessageSubject ms
         where ms.subject like '%临分编辑%')



框架是SSH ,hibernate3,报错信息为:


Java code
]] Root cause of ServletException.
java.lang.NullPointerException
    at org.hibernate.hql.ast.tree.CaseNode.getDataType(CaseNode.java:17)
    at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:143)
    at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:712)
    at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:536)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645)
    Truncated. see log file for complete stacktrace
> 


网上搜索了下,说要配置这个
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop> 
但我这样配置之后仍旧报错,请高手解决,谢谢

------解决方案--------------------
case when 最后一个逻辑加一个else 啊。。。不然你subjectType除了C,R,E以外的 都会出现null,进而空指针了。。。
------解决方案--------------------
掉了 else。
case when then ......else end
------解决方案--------------------
探讨
OMG...
我用findByHql(hql.toString(), pageNo, pageSize);它就报错
但我用findBySql(hql.toString());它就不报错,各位牛人解释下

------解决方案--------------------
探讨
那也不至于我那个报错吧?

引用:
引用:
OMG...
我用findByHql(hql.toString(), pageNo, pageSize);它就报错
但我用findBySql(hql.toString());它就不报错,各位牛人解释下


findByHql执行的是HQL语句。。HQL语句是用实体查询,基于……