Question

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.

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top