2010-11-22 60 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(); 

希望帮助...