Java / Hibernate: Could not resolve property with nested object criterias

Viewed 36035

I'm having problems with a Hibernate criteria. I'm trying to make a Criteria where I look at the id of a member object of the class the query returns.

For example:

Criteria crit = session.createCriteria(Enquiry.class);
crit.add(Expression.eq("lecture.admin.id", userId));`

The result of this is an exception:
org.hibernate.QueryException: could not resolve property: lecture.admin.id of: xxx.yyy.Enquiry

The Enquiry class does contain the lecture variable, which in turn contains the admin variable. I have tried using lecture.id and that works fine.

Is there a limit to the number of levels you can go down the object hierarchy like this?

Thanks!

Code snippets:

public class Lecture extends TransferItem {  
  private User admin;  
  public User getAdmin() {  
    return admin;  
  }
}

The 'User' class extends the Person class, which in turn extends an Itemclass, which has the getId()method:

public Integer getId() {  
  if (id != null) {  
    return id;  
  }  
  return TransferBean.NOT_SET;  
}

From the Hibernate mapping XML:

<class name="User" table="user">  
  <id column="user_id" name="id">
    <generator class="increment"/>  
  </id>
  ...

<class name="Lecture" table="lecture">  
  <many-to-one class="User" column="user_fk" lazy="false" name="admin"/>`  

This is the user table:

mysql> show columns from user;  
+-----------------+--------------+------+-----+---------+-------+  
| Field           | Type         | Null | Key | Default | Extra |  
+-----------------+--------------+------+-----+---------+-------+  
| user_id         | int(11)      | NO   | PRI |         |       |   
| firstname       | varchar(50)  | YES  |     | NULL    |       |   
| lastname        | varchar(50)  | YES  |     | NULL    |       |   
| signature       | varchar(16)  | YES  |     | NULL    |       |   
| email_signature | varchar(256) | YES  |     | NULL    |       |   
| password        | varchar(32)  | YES  |     | NULL    |       |   
| phone           | varchar(16)  | YES  |     | NULL    |       |   
| email           | varchar(255) | YES  | UNI | NULL    |       |   
| lecturer_fk     | int(11)      | YES  | MUL | NULL    |       |   
| access          | int(11)      | YES  |     | NULL    |       |   
| deleted         | tinyint(1)   | YES  |     | NULL    |       |   
+-----------------+--------------+------+-----+---------+-------+  
11 rows in set (0.02 sec)`  
2 Answers
Related