嗨,我有一个情况需要执行此选择语句
SELECT c.*, count(r.competitorid) as num_comp, num_event.num_events
from competition c left join regcomp r on c.competitionid = r.competitionid
left join
(
select competition.competitionid, count(e.competitionid) as num_events
from competition left join `event` e on competition.competitionid = e.competitionid
group by competition.competitionid
) as num_event on c.competitionid = num_event.competitionid
)
AS winners ON winners.competitionid = c.competitionid;
我的问题是我不知道遵循什么模式,或者是否需要调用一组方法来为此表创建数据源。我可以创建一个 IndexedContainer 并添加容器属性,然后将其添加到 Vaadin 表中,这就是我正在做的事情 - 但问题是当我尝试保留数据时,如果不这样做,我以后将无法使用 JPA在开始时使用它。
JPA 允许您通过执行 setVisibleColumns("parent.child") 非常方便地通过外键访问引用表,因此理论上可以通过选择正确的条目实体来显示有关单行的任何信息。
但是,如果我想创建一个显示其中一列中的计数的表,我该怎么办,显然计数不是实体的一部分 - 但如果它不是实体的一部分,我该如何利用这些好处表上的 JPA 包含由 avg()、count() 等生成的数据。
附注该查询检索一个表,其中显示所有比赛以及该比赛中有多少参赛者和项目。
最佳答案
这取决于您使用的 JPA 提供商。 使用 Hibernate 时,您可以使用 this post 中提到的计算属性。 .
然后它给出这样的注释:
@Formula("PRICE*1.155")
private float finalPrice;
甚至更复杂
@Formula("(select min(o.creation_date) from Orders o where o.customer_id = id)")
private Date firstOrderDate;
看看 other post有关此 Hibernate 功能的更多详细信息。
对于 EclipseLink/Toplink 我知道没有解决问题的方法
关于java - 将选择计数添加到 vaadin 数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26727478/