title: Criteria api restriction with InheritanceType.JOINED
body: <p>I'm stuck with the following problem - i have a MappedSuperClass entity with InheritanceType.JOINED, and some entities, extending that superclass. And when i try to query this entity with criteria api, i'm getting strange result set, which contains only one of sub entities.</p>
  
  <p>The code as follows:
  Base parent class:</p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.JOINED)
  public class Parent
  {
      @Id
      private long id;
      /** getters and setters */
  }
  </code></pre>
  
  <p>Mapped superclass, which contains shared attribute:</p>
  
  <pre><code>@MappedSuperclass
  public class Attributes extends Parent
  {
      @Column
      private String name;
      /** getters and setters */
  }
  </code></pre>
  
  <p>First subentity:</p>
  
  <pre><code>@Entity
  @Table(name = "classA")
  public class SubClassA extends Attributes
  {
      @Column
      private String lastName;
      /** getters and setters */
  }
  </code></pre>
  
  <p>Second subentity:</p>
  
  <pre><code>@Entity
  @Table(name = "classB")
  public class SubClassB extends Attributes
  {
      @Column
      private String secondName;
      /** getters and setters */
  }
  </code></pre>
  
  <p>And the criteria:</p>
  
  <pre><code>Criteria criteria = session.createCriteria(Parent.class);
  Criterion restrictions = Restrictions.ilike("name", "n%");
  Junction conditionGroup = Restrictions.conjunction();
  conditionGroup.add(restrictions);
  criteria.add(conditionGroup);
  </code></pre>
  
  <p><strong>As a result</strong>, i've got the following sql:</p>
  
  <pre><code>select 
    this_.id           as id1_0_0_, 
    this_1_.name       as name1_1_0_, 
    this_1_.lastName   as lastName2_1_0_, 
    this_2_.name       as name1_2_0_, 
    this_2_.secondName as secondNa2_2_0_, 
  case 
    when this_1_.id is not null then 1 
    when this_2_.id is not null then 2 
    when this_.id   is not null then 0 
  end as clazz_0_ 
  from Parent this_ 
    left outer join classA this_1_ on this_.id=this_1_.id 
    left outer join classB this_2_ on this_.id=this_2_.id 
  where 
    (lower(this_1_.name) like ?)
  </code></pre>
  
  <p>As i can see, the selection is nearly i've expected, except the "where" clause, which includes only this_1_.name, which is alias for classA, but not classB. Both tables (classA and classB) are filled with data, but, the result set contains data only from classA table.</p>
  
  <p>Other observation shows, that, if i change InheritanceType to TABLE_PER_CLASS, the result would be correct, because it uses union:</p>
  
  <pre><code>select 
    this_.id as id1_0_0_, 
    this_.name as name1_1_0_, 
    this_.lastName as lastName2_1_0_, 
    this_.name as name1_2_0_, 
    this_.secondName as secondNa2_2_0_, 
    this_.clazz_ as clazz_0_ 
  from 
    ( 
      select 
        id, 
        cast(null as varchar(100)) as name, 
        cast(null as varchar(100)) as lastName, 
        cast(null as varchar(100)) as secondName, 
        0 as clazz_ 
      from Parent 
        union all 
        select 
          id,
          name, 
          lastName, 
          cast(null as varchar(100)) as secondName, 
          1 as clazz_ 
        from classA 
        union all select 
          id, 
          name, 
          cast(null as varchar(100)) as lastName, 
          secondName, 
          2 as clazz_ from classB 
    ) this_ where (lower(this_.name) like ?)
  </code></pre>
  
  <p>So, to make a long story short, the there is a question - is there a way to make restriction queries for InheritanceType.JOINED, which would cover ALL subclasses? Something like:</p>
  
  <pre><code>where 
  (  (lower(this_1_.name) like ?) or
     (lower(this_2_.name) like ?) 
  )
  </code></pre>
  
  <p>Thanks in advance for your replies!</p>