title: Problems with scalar values in native hibernate/jpa query using annotations
body: <p>I'm trying to run a simple SQL query containig a group by clause.</p>
  
  <p>HistoryEntity:</p>
  
  <pre><code>@Entity
  @NamedNativeQueries(value = {
      @NamedNativeQuery(name = HistoryEntity.FIND_ALL_BY_REFERENCE,
                        query = "SELECT h.id, h.reference, h.lrn "
                            + "FROM dataHistory h "
                            + "WHERE h.reference = :referenceNumber OR h.lrn = :referenceNumber",
                        resultSetMapping = HistoryEntity.FIND_ALL_BY_REFERENCE_MAPPING),
      @NamedNativeQuery(name = HistoryEntity.FIND_REFERENCE_BY_LRN,
                        query = "SELECT h.reference as reference "
                            + "FROM dataHistory h "
                            + "WHERE h.lrn = :lrn "
                            + "GROUP BY h.reference",
                        resultSetMapping = "resultMapping")                   
  })
  @SqlResultSetMappings(value = {
      @SqlResultSetMapping(name = HistoryEntity.FIND_ALL_BY_REFERENCE_MAPPING, entities = {
              @EntityResult(entityClass = HistoryEntity.class, fields = {
                  @FieldResult(name = "id", column = "id"),
                  @FieldResult(name = "reference", column = "reference"),
                  @FieldResult(name = "lrn", column = "lrn")
              })
      }),
      @SqlResultSetMapping(name = "resultMapping", columns = {
              @ColumnResult(name = "reference")
      })
  })
  public class HistoryEntity implements Serializable {
  
  /**
   * @param referenceNumber Referenz (LRN oder BRN)
   * @param brnList Liste von BRNs
   */
  public static final String FIND_ALL_BY_REFERENCE = "HistoryEntity.findAllByReference";
  
  public static final String FIND_ALL_BY_REFERENCE_MAPPING = "HistoryEntity.findAllByReferenceMapping";
  
  private Integer id;
  
  private String reference;
  private String lrn;
  
  public HistoryEntity() {}
  
  @Id
  public Integer getId() {
      return id;
  }
  
  public void setId(Integer id) {
      this.id = id;
  }
  
  public String getReference() {
      return reference;
  }
  
  public void setReference(String reference) {
      this.reference= reference;
  }
  
  public String getLrn() {
      return lrn;
  }
  
  public void setLrn(String lrn) {
      this.lrn = lrn;
  }
  </code></pre>
  
  <p>In the service class, I execute the query as follow:</p>
  
  <pre><code>Query query = entityManager.createNamedQuery("myQuery");
  query.setParameter("lrn", lrn);
  
  List resultList = query.getResultList();
  </code></pre>
  
  <p>Depending on the result of the query, the list contains java.lang.Character's:</p>
  
  <p>Case 1:<br>
  SQL-Result (if I'm running the sql in a sql client):<br>
  | Reference |<br>
  | 123456780678MMM |<br>
  | 123456781678MMM |<br>
  | 123456782678MMM |<br>
  | 123456783678MMM |  </p>
  
  <p>Java-List-Result (in Java Debug View):<br>
  [1, 1, 1, 1]</p>
  
  <p>Case 2:<br>
  SQL-Result:<br>
  | Reference |<br>
  | 123456780678MMM |  </p>
  
  <p>Java-List-Result:<br>
  [1]</p>
  
  <p>I'm looking for a way to run a simple sql query with scalar values (using hibernate/jpa) to get as result a list with the values of the result.</p>
  
  <p>Is there any way to do this without using the criteria api?</p>
  
  <p>If you need more information, let me know!</p>
  
  <p>Many thanks in advance for your help.</p>
  
  <p>Marco</p>