Note that there are some explanatory texts on larger screens.

plurals
  1. POJava / Hibernate: Could not resolve property with nested object criterias
    primarykey
    data
    text
    <p>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.</p> <p>For example: </p> <pre><code>Criteria crit = session.createCriteria(Enquiry.class); crit.add(Expression.eq("lecture.admin.id", userId));` </code></pre> <p>The result of this is an exception:<br> <code>org.hibernate.QueryException: could not resolve property: lecture.admin.id of: xxx.yyy.Enquiry</code></p> <p>The <code>Enquiry</code> class does contain the lecture variable, which in turn contains the admin variable. I have tried using <code>lecture.id</code> and that works fine.</p> <p>Is there a limit to the number of levels you can go down the object hierarchy like this?</p> <p>Thanks!</p> <p>Code snippets:</p> <pre><code>public class Lecture extends TransferItem { private User admin; public User getAdmin() { return admin; } } </code></pre> <p>The 'User' class extends the <code>Person</code> class, which in turn extends an <code>Item</code>class, which has the <code>getId()</code>method:</p> <pre><code>public Integer getId() { if (id != null) { return id; } return TransferBean.NOT_SET; } </code></pre> <p>From the Hibernate mapping XML: </p> <pre><code>&lt;class name="User" table="user"&gt; &lt;id column="user_id" name="id"&gt; &lt;generator class="increment"/&gt; &lt;/id&gt; ... &lt;class name="Lecture" table="lecture"&gt; &lt;many-to-one class="User" column="user_fk" lazy="false" name="admin"/&gt;` </code></pre> <p>This is the <code>user</code> table: </p> <pre><code>mysql&gt; 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)` </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload