Add entity with InheritanceType.JOINED to native query : <p>I am struggling to get native queries to work with <code>InheritanceType.JOINED</code>. From the Hibernate <a href="https://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html/ch13.html#d5e3844">documentation</a> I have found:</p>

<blockquote>
  <h1>13.1.6. Handling inheritance</h1>
  
  <p>Native SQL queries which query for entities that are mapped as part of an inheritance must include all properties for the baseclass and all its subclasses.</p>
</blockquote>

<p>Using the following two entities:</p>

<pre class="lang-java prettyprint-override"><code>@Data
@Entity
@Table(name = "my_super")
@EqualsAndHashCode(of = {"id"})
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class MySuper {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private long id;

}
</code></pre>

<p>And:</p>

<pre class="lang-java prettyprint-override"><code>@Data
@Entity
@Table(name = "my_sub_a")
@EqualsAndHashCode(callSuper = true)
public class MySubA extends MySuper {

    @Column(name = "x")
    private int x;

}
</code></pre>

<p>When I try to create a native query using:</p>

<pre class="lang-java prettyprint-override"><code>Object actual = session
    .createNativeQuery("SELECT {s.*} FROM my_super {s} LEFT JOIN my_sub_a {a} USING (id)")
    .addEntity("s", MySuper.class)
    .getSingleResult();
</code></pre>

<p>It translates to the query:</p>

<pre><code>SELECT s.id as id1_1_0_, s_1_.x as x1_0_0_, case when s_1_.id is not null then 1 when s.id is not null then 0 end as clazz_0_ FROM my_super s LEFT JOIN my_sub_a  a  USING (id) 
</code></pre>

<p>And then fails with:</p>

<pre><code>javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
Caused by: org.h2.jdbc.JdbcSQLException: Column "S_1_.X" not found; SQL statement:
</code></pre>

<p>So we observe the alias injection doing its work, figuring out that it may need the <code>x</code> column of <code>my_sub_a</code> as well. It is however unable to figure out the alias for <code>my_sub_a</code>. How should my code be modified so that this alias is connected properly as well?</p>

<p>My code is available at <a href="https://gist.github.com/JWGmeligMeyling/51e8a305f3c268eda473511e202f76e8">https://gist.github.com/JWGmeligMeyling/51e8a305f3c268eda473511e202f76e8</a> for easy reproduction of my issue.</p>

<p><em>(I am aware that this query can easily be expressed in JPQL or HQL as well, and can even be achieved using the <code>EntityManager</code> and <code>Session</code> API's. I do however want to use this in a more complex query, that I simplified to all details required for this question).</em></p>
