2010-11-22 25 views
1

我正在使用條件來獲取包含活動用戶的通知列表。問題是,我得到以下錯誤:hibernate:使用標準訪問對象內的對象

org.hibernate.QueryException: could not resolve property: user.active of: com.company.Notification 

其他然後檢查用戶是活動的,我需要檢查通知是我想要的類型。這裏是我的代碼:

session.createCriteria("com.company.Notification") 
    .add(Restrictions.or(Restrictions.eq("type", "email"), 
    .add(Restrictions.eq("user.active", true)).list(); 

通知有一個字段User user這反過來有一個字段Boolean active

我在看這個頁面:https://forum.hibernate.org/viewtopic.php?t=948576&highlight=subproperty

,但我仍然不groking如何創建標準訪問父對象和子對象中的某些內容。

回答

6

試試這個:

session.createCriteria("com.company.Notification") 
    .add(Restrictions.or(Restrictions.eq("type", "email") 
    .createCriteria("user") // this creates the join on the user table... 
    .add(Restrictions.eq("active", true)).list(); 

希望幫助...