hibernate 难道不支持case when then end 吗?[已解决,谢谢关注]

hibernate 版本:网上最新的hibernate-3.2.0.ga
执行hql:
select case when c.id>'1' then '111' else '333' END from QuCodeRegion c
报错:
QueryException: undefined alias: case [select case when c.id>'1' then '111' else '333' END from QuCodeRegion c]

如果将case 放到where语名后面,则一切正常.
select c.id from QuCodeRegion c where case when c.id>'1' then '111' else '333' END='111'
一切正常.
这是为什么,难道hibernate 不支持这种语法.
但hibernate的测试用例里明明有这样的程序(一部分代码):


[code]

// $Id: ASTParserLoadingTest.java 9531 2006-03-02 03:14:31Z steve.ebersole@jboss.com $
package org.hibernate.test.hql;

public class ASTParserLoadingTest extends TestCase {

public ASTParserLoadingTest(String name) {
super( name );
}

public void testSelectClauseCase() {
Session s = openSession();
Transaction t = s.beginTransaction();
Human h = new Human();
h.setBodyWeight( (float) 74.0 );
h.setHeight(120.5);
h.setDescription("Me");
h.setName( new Name("Gavin", 'A', "King") );
h.setNickName("Oney");
s.persist(h);
String name = (String) s.createQuery("select case nickName when 'Oney' then 'gavin' when 'Turin' then 'christian' else nickName end from Human").uniqueResult();
assertEquals(name, "gavin");
String result = (String) s.createQuery("select case when bodyWeight > 100 then 'fat' else 'skinny' end from Human").uniqueResult();
assertEquals(result, "skinny");
s.delete(h);
t.commit();
s.close();
}
}

[/code]

解决办法:
终于发现问题了,配置文件问题.
当查询解析器配置为


代码

<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>


出错
配置为

代码

<property name="org.hibernate.hql.ast.ASTQueryTranslatorFactory"</property>


能正常运行.
怀疑第一个解析器有问题.
感谢:together、BirdGu的帮助!
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值