2011-07-21 120 views
1

我有一個這樣的實體:如何在HQL使用派生的財產where子句

public class Account{ 
    private String code; 
    @ManyToOne 
    private Account ledgerAccount; 


    public String getCode(){ 
     return code; 
    } 

    public String getFullCode(){ 
     return ledgerAccount.getCode()+code; 
    } 
} 

所以,fullCode是派生的財產,我想在我的HQL查詢使用它,我怎樣才能實現這一目標?

回答

3

中創建一個模型叫fullCode財產和註釋這樣說:

@Formula( 「ledgerAccount.code +代碼」) 私人字符串fullCode;

,改變你的getFullCode()方法:

public String getFullCode() { 
    return fullCode; 
} 

,然後在HQL:

select * from Account where fullCode = ? 

如果你還沒有,檢查this page更多的例子。

+0

謝謝你的提示,使用這個公式它的工作:@Formula(「(從帳戶a中選擇a.code‖代碼,其中a.id = ledgeraccount_id)」) – blow