mko*_*yak 1 hibernate detachedcriteria
我正在使用条件来获取包含活动用户的通知列表.问题是我收到以下错误:
org.hibernate.QueryException: could not resolve property: user.active of: com.company.Notification
Run Code Online (Sandbox Code Playgroud)
除了检查用户是否活动之外,我需要检查通知是否是我想要的类型.这是我的代码:
session.createCriteria("com.company.Notification")
.add(Restrictions.or(Restrictions.eq("type", "email"),
.add(Restrictions.eq("user.active", true)).list();
Run Code Online (Sandbox Code Playgroud)
通知具有一个字段User user,该字段又具有字段Boolean active
我正在看这个页面:https://forum.hibernate.org/viewtopic.php?t = 948576&highlight = subproperty
但我仍然不知道如何创建一个访问父对象和子对象中的东西的条件.
试试这个:
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();
Run Code Online (Sandbox Code Playgroud)
希望有帮助......