case when 无法执行,为什么

Hql 语句:
select sum(case when to_char(t.accountinoutDate,'yyyymmdd hh24:mi:ss') < to_char(to_date('2010-07-01 00:00:00','yyyy-mm-dd hh24:mi:ss'),'yyyymmdd hh24:mi:ss') then (case when t.accountinoutDirection = 0 then 1 else -1 end) * t.accountinoutMoney end) as startmoney, t.inneraccountsCode,t.orgCode from FundAccountinout t
group by t.inneraccountsCode,t.orgCode

报错:
17:43:09,312 ERROR [[default]] Servlet.service() for servlet default threw exception
org.hibernate.hql.ast.QuerySyntaxException:[color=red] fundAccountinout is not mapped[/color] [select (case when t.accountinoutDirection = 0 then 1 else -1 end) * t.accountinoutMoney as startmoney, t.inneraccountsCode,t.orgCode from fundAccountinout t where to_char(t.accountinoutDate,'yyyymmdd hh24:mi:ss') <= to_char(to_date('2010-07-30 00:00:00','yyyy-mm-dd hh24:mi:ss'),'yyyymmdd hh24:mi:ss') and t.memberCode = ? group by t.inneraccountsCode,t.orgCode]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:251)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:923)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:921)
at com.golden.soft.common.system.dao.HibernateGenericDao.getResultCount(HibernateGenericDao.java:635)
at com.golden.soft.common.system.dao.HibernateGenericDao.queryForPageByHql(HibernateGenericDao.java:330)

原因是红色部分,即类名写错了,严格区分大小写
case when在hibernate中是可以使用的,但是语法比较严格
hql语句应改为(注意红色部分)
select sum(case when to_char(t.accountinoutDate,'yyyymmdd hh24:mi:ss') < to_char(to_date('2010-07-01 00:00:00','yyyy-mm-dd hh24:mi:ss'),'yyyymmdd hh24:mi:ss') then [color=red]([/color](case when t.accountinoutDirection = 0 then 1 else -1 end) * t.accountinoutMoney[color=red])[/color] end) as startmoney, t.inneraccountsCode,t.orgCode from FundAccountinout t
group by t.inneraccountsCode,t.orgCode
另外注意,xml中需要<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值