2012-09-26 72 views
0

我運行一個HQL,與右連接:休眠 - 選擇從連接表的特定列

select sum(banks.money) from banks right join banks.account where banks.account = :account and (banks.date < :date or banks.date is null) group by banks.account, banks.date 

休眠其轉換爲類似的東西:我想Hibernate來

select sum(banks.money) from banks right join accounts on banks.account_id = accounts.account_id where banks.account_id = someId and (banks.date < someDate or banks.date is null) .... 

從賬戶表(我可以擁有一個不在銀行表中的賬戶)中的account_id字段,而不是從銀行表中獲取。

有什麼辦法明確告訴hibernate連接表執行哪一列?在這兩種情況下

select sum(banks.money) 
from banks 
    right join banks.account acct 
     with acct.id = :accountId 
where banks.date < :date 
    or banks.date is null 
group by banks.account, banks.date 

,特別注意給予別名:

回答

0

格式幫助...反正...

select sum(banks.money) 
from banks 
    right join banks.account acct 
where acct = :account 
    and (banks.date < :date or banks.date is null) 
group by banks.account, banks.date 

雖然就個人而言,我將它添加到加盟條件加入協會並將其用作限定詞

+0

完美工作 非常感謝 – yaarix