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
但我我仍然不知道如何创建一个访问父对象和子对象中某些内容的标准。
I am using criteria to get a list of notifications that contains users that are active. The problem is that i get the following error:
org.hibernate.QueryException: could not resolve property: user.active of: com.company.Notification
Other then checking that the user is active i need to check that the notification is of a type that i want. Here is my code:
session.createCriteria("com.company.Notification")
.add(Restrictions.or(Restrictions.eq("type", "email"),
.add(Restrictions.eq("user.active", true)).list();
Notification has a field User user
which in turn has a field Boolean active
i am looking at this page: https://forum.hibernate.org/viewtopic.php?t=948576&highlight=subproperty
but i am still not groking how to create a criteria that accesses something in the parent object and in child object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
希望有帮助...
try this:
hope that helped...