开发者

hibernate: using criteria to access objects within objects

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.


try this:

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();

hope that helped...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜