JPA仅在联合中执行第一条select语句? [英] JPA only executes first select statement in union?

查看:97
本文介绍了JPA仅在联合中执行第一条select语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个JPQL语句,该语句结合了多个select语句,每个选择语句选择一个不同的字符串常量.查询的简化版本如下所示:

I've written a JPQL statement that unions multiple select statements, each of which selects a different string constant. A simplified version of the query would look something like this:

SELECT DISTINCT 'A' AS widget_type
  FROM WidgetA widgetA
  WHERE widgetA.creationTimestamp > :cutoff
UNION SELECT DISTINCT 'B' AS widget_type
  FROM WidgetB widgetB
  WHERE widgetB.creationTimestamp > :cutoff

该查询不会导致任何错误,但没有得到我期望的结果.我看到生成的SQL没有任何联合-它仅从第一个选择查询表:

The query doesn't cause any errors but I'm not getting the result I expect. I see that the generated SQL doesn't have any unions - it only queries the table from the first select:

select distinct 'A' as col_0_0_ 
from widget_a widget0_
where widget0_.creation_timestamp>?

在第一个select语句之后,JPA会无视所有内容吗?如果有什么不同,我将使用Hibernate 4.1.9作为JPA实现以及MySQL数据库.

Is there an obvious reason why JPA would disregard everything after the first select statement? If it makes any difference, I am using Hibernate 4.1.9 as the JPA implementation, with a MySQL database.

推荐答案

JPQL 不具有UNION这样的概念.因此,任何具有它的查询"都不是JPQL,因此应被视为无效的JPQL( DataNucleus JPA 当然可以)

JPQL has no such concept as UNION. So consequently any "query" that has it is not JPQL and so ought to be rejected as invalid JPQL (which DataNucleus JPA certainly would do)

这篇关于JPA仅在联合中执行第一条select语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆