title: Retrieving Polymorphic Hibernate Objects Using a Criteria Query
body: <p>In my model I have an abstract "User" class, and multiple subclasses such as Applicant, HiringManager, and Interviewer. They are in a single table, and I have a single DAO to manage them all. </p>
  
  <p>User:</p>
  
  <pre><code>@Entity
  @Table(name="User")
  @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(
      name="role",
      discriminatorType=DiscriminatorType.STRING
  )
  public abstract class User extends BaseObject implements Identifiable&lt;Long&gt; ...
  </code></pre>
  
  <p>HiringManager (for example):</p>
  
  <pre><code>@Entity
  @DiscriminatorValue("HIRING_MANAGER")
  public class HiringManager extends User ...
  </code></pre>
  
  <p>Now if I wanted to, say, get all the hiring managers that are not associated with a department, how would I do that? I imagine it would look something like:</p>
  
  <pre><code>DetachedCriteria c = DetachedCriteria.forClass(User.class);
  c.add(Restrictions.eq("role", "HIRING_MANAGER"));
  c.add(Restrictions.isNull("department"));
  List&lt;User&gt; results = getHibernateTemplate().findByCriteria(c);
  </code></pre>
  
  <p>But when I run this, Hibernate complains "could not resolve property: role" (Which actually makes sense because the User class really doesn't have an explicit role property)<br>
  So what's the right way to do what I'm trying to do?</p>