HQL查询多对多关系中的最新时间戳

时间:2017-03-25 22:05:16

标签: sql database hibernate jpa hql

DB

     A         B                A_B
   -----     -----             ------
    id         id               A_id
    name       time_stamp       B_id
               desc

模型

     A         B                
   -----     -----           
    id         id             
    name       time_stamp
    [B]        desc

我正在尝试创建一个HQL查询,它将拉出所有A,其中B的time_stamp是最新的,如果desc是'Done',则只返回该行。这是我现在拥有的:

select a from A a
        inner join a.B b
        where b.time_stamp in (
        select max(selectedB.time_stamp) from B selectedB
        where selectedB.id = b.id)
        and b.desc = 'Done'

这似乎不起作用。它似乎只尊重desc而不关心时间选择。有什么想法吗?

0 个答案:

没有答案