title: Can Hibernate Criteria query for subclasses using Restrictions.in?
body: <p>I have a number of classes mapped as an inheritance hierarchy into a single table.</p>
  
  <p>I would like to use the following <code>Criteria</code> query but this results in a <code>ClassCastException</code> since <code>Class</code> cannot be cast to <code>String</code>.</p>
  
  <pre><code>Set&lt;Class&gt; childClasses = new HashSet&lt;&gt;();
  childClasses.add(Child1.class);
  childClasses.add(Child2.class);
  
  session.createCriteria(Parent.class)
         .add(Restrictions.in("class", childClasses)
         .list();
  </code></pre>
  
  <p>I note that Hibernate does support specifying a single class using <code>Restrictions.eq("class", childClass)</code> so I can workaround by using a <code>Disjunction</code>'. I also know that this would work if my resriction was based on the discriminator strings for each subclass but I would prefer not to use these.</p>
  
  <p>It is possible to use <code>Criteria</code> in this manner? The accepted answer to <a href="https://stackoverflow.com/questions/11082364/java-hibernate-criteria-select-subclass">this question</a> suggests that it works when the class is a property of the class you are basing your <code>Criteria</code> on but it doesn't seem to work in the case I've shown above.</p>