Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 在case-when语句中休眠子查询_Hibernate_Subquery_Case - Fatal编程技术网

Hibernate 在case-when语句中休眠子查询

Hibernate 在case-when语句中休眠子查询,hibernate,subquery,case,Hibernate,Subquery,Case,我在case-when语句中执行HQL子查询时遇到问题 这是我的密码: select case when a.entityId is null then 'invalid' else (select b.entityName from tblName b where b.entityId =a.entityId) end from tblEntity a 谢谢你的帮助 好的。。这是完整的堆栈跟踪 ERROR org.hibernate.hql.PARSER - <AST&

我在case-when语句中执行HQL子查询时遇到问题

这是我的密码:

select case when a.entityId is null then 'invalid' else 
   (select b.entityName from tblName b where b.entityId =a.entityId) 
   end from tblEntity a
谢谢你的帮助

好的。。这是完整的堆栈跟踪

ERROR org.hibernate.hql.PARSER - <AST>:0:0: unexpected AST node: query
Exception in thread "Thread-5" org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [select case when a.entityId is null then 'invalid' else 
       (select b.entityName from tblName b where b.entityId =a.entityId) 
       end from tblEntity a]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
    at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
    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:1651)

Hibernate不支持此功能。 但确实存在一个解决办法。 在数据库中创建一个视图,然后使用HQL通过java获取结果

创建或替换强制视图VW\u实体\u值EntityValue 像 当a.entityId为null时选择case,然后选择“invalid”,否则 从tblName b中选择b.entityName,其中b.entityId=a.entityId 从第a节结束

从HQL的文档中:

14.13。子查询

对于支持子选择的数据库,Hibernate支持查询中的子查询。子查询必须用括号括起来,通常由SQL聚合函数调用括起来。即使是相关子查询,也允许在外部查询中引用别名的子查询

从猫变成胖猫 其中fatcat.weight> 从DomesticCat中选择avgcat.weight 从家猫变成猫 其中cat.name=some 从名称中选择name.昵称作为名称 从猫变成猫 不存在的地方 从猫作为配偶,其中mate.mate=Cat 从家猫变成猫 猫名不在哪里 从名称中选择name.昵称作为名称 选择cat.id,从cat.kitten kit中选择maxkit.weight 从猫变成猫
请注意,HQL子查询只能出现在select或where子句中。

它给出了什么错误?org.hibernate.HQL.ast.QuerySyntaxException:意外的ast nodestill无线索!编辑问题,并添加完整的堆栈跟踪!谢谢你的回复。。。当我使用不带case-when的子查询时,它可以工作,但是当我在case-when语句中使用它时,它就不能工作了。