code: public SQLQuery getQueryInstance(String nativeQuery, EntityMetadata m)
      {
          s = getStatelessSession();
  
          SQLQuery q = s.createSQLQuery(nativeQuery).addEntity(m.getEntityClazz());
  
          List<String> relations = m.getRelationNames();
          if (relations != null)
          {
              for (String r : relations)
              {
                  Relation rel = m.getRelation(m.getFieldName(r));
                  String name = MetadataUtils.getMappedName(m, m.getRelation(r), kunderaMetadata);
                  if (!((AbstractAttribute) m.getIdAttribute()).getJPAColumnName().equalsIgnoreCase(
                          name != null ? name : r)
                          && rel != null
                          && !rel.getProperty().isAnnotationPresent(ManyToMany.class)
                          && !rel.getProperty().isAnnotationPresent(OneToMany.class)
                          && (rel.getProperty().isAnnotationPresent(OneToOne.class)
                                  && StringUtils.isBlank(rel.getMappedBy()) || rel.getProperty().isAnnotationPresent(
                                  ManyToOne.class)))
                  {
                      q.addScalar(name != null ? name : r);
                  }
              }
          }
          return q;
      }
docs: Gets the query instance.
  
  @param nativeQuery
  the native query
  @param m
  the m
  @return the query instance