title: Hibernate Native Query with 5.2.10
body: <p>Under Hibernate &lt; 5.2, it was possible to have generic SQL queries like</p>
  
  <pre><code>String sql = "select a, b, sum (c) csum from a group by a, b";
  SQLQuery q = session.createSqlQuery (sql);
  q
      .addScalar ("a", IntegerType.INSTANCE)
      .addScalar ("b", IntegerType.INSTANCE)
      .addScalar ("csum", IntegerType.INSTANCE);
  q.setResultTransformer (new AliasToBeanResultTransformer (RankingModel.class));
  List&lt;RankingModel&gt; results = q.list ();
  </code></pre>
  
  <p>Where <code>RankingModel</code> looks like:</p>
  
  <pre><code>public class RankingModel
  {
      public int a, b, csum;
  }
  </code></pre>
  
  <p>However, with 5.2, <code>addScalar()</code>, <code>setResultTransformer()</code> have all been deprecated, with the recommendation to use <code>session.createNativeQuery()</code> instead. The nearest equivalent to the above I have is:</p>
  
  <pre><code>String sql = "select a, b, sum (c) csum from a group by a, b";
  NativeQuery&lt;RankingModel&gt; q = session.createNativeQuery (sql, RankingModel.class);
  List&lt;RankingModel&gt; results = q.list ();
  </code></pre>
  
  <p>However, this code fails with:</p>
  
  <pre><code>org.hibernate.MappingException: Unknown entity: ... RankingModel] with root cause
  org.hibernate.MappingException: Unknown entity: ... RankingModel
      at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:620)
      at org.hibernate.engine.spi.SessionFactoryImplementor.getEntityPersister(SessionFactoryImplementor.java:335)
      at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:358)
      at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:411)
      at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:378)
      at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:180)
      at org.hibernate.loader.custom.sql.SQLCustomQuery.&lt;init&gt;(SQLCustomQuery.java:71)
      at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.createQueryPlan(NativeQueryInterpreterStandardImpl.java:70)
      at org.hibernate.engine.query.spi.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:213)
      at org.hibernate.internal.AbstractSharedSessionContract.getNativeQueryPlan(AbstractSharedSessionContract.java:550)
      at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:992)
      at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:148)
  </code></pre>
  
  <p>Anyone have any idea what I'm missing?</p>