title: How to work with SQL Views in Spring JPA?
body: <p>I'm currently working on a project with Spring and HANA DB.</p>
  
  <p>I have already an Webservice which is working properly, but I need to select a View from my HANA DB(created outside of the Spring Webservice).</p>
  
  <p>My view is made from 2 tables, 4 of its fields are SUM of one column from one of the tables(which counts how much of each of each 4 possible values and shows that as a number in each of the 4 fields).</p>
  
  <p>I read about in some Spring JPA posts that it should work properly with a simple select, my questions are:</p>
  
  <p>I usually make selects like this:</p>
  
  <pre><code>TypedQuery&lt;name_of_the_model_class&gt; query = em.createQuery("SELECT c FROM NameOfTheTable ORDER BY c.some_field DESC WHERE c.name =?1 ", name_of_the_model_class.class);
  query.setParameter(1, name_to_search);
  </code></pre>
  
  <p>And then after that I just return the list to the Controller and the Controller shows that in a JSON.</p>
  
  <p>The problem is, I have created this View in Eclipse, using directly SQL code in HANA DB, without creating it at the Webservice.</p>
  
  <p>I would like to know, <strong>is there a way to select like I showed above, returning it without a model class?</strong> <strong>It would just need a class with exactly the same fields like a model class but without @Entity annotation on it?</strong></p>
  
  <p>OR <strong>is there a way to create a view like a model class in Spring JPA? If there is a way, what are the annotations to make it work?</strong> </p>
  
  <p><strong>Spring JPA would not accept me to return it without a class would it?</strong></p>
  
  <p>I read plenty posts but didn't found it, even in the Manual it doesn't give clear specification or examples.</p>
  
  <p>Thanks a lot for your time, if I didn't explained it well pls tell me, I'm really stuck on this.</p>
  
  <p><strong>More info(my latest try):</strong>
  My entire search function at the DAO:</p>
  
  <pre><code>public List&lt;IncidentStatusResultsUser&gt; getIncidentStatusByUser(String userID) throws ParseException {   
  
          List&lt;IncidentStatusResultsUser&gt; resultList = em.createQuery("SELECT c FROM USERSTATUS ORDER BY c.uploadDateTime DESC WHERE c.userID=?1 ").setMaxResults(48).getResultList();
  
  
          Collections.reverse(resultList);
  
          return resultList;              
      }
  </code></pre>
  
  <p>I have created a class to just receive the data with the same fields of the view:</p>
  
  <pre><code>public class IncidentStatusResultsUser {
  
      private Date uploadDateTime ;
      private int status1;
      private int status2;
      private int status3;
      private int status4;
  
      //All gets and sets ommited
      public IncidentStatusResultsUser (Date uploadDateTime, long status1, long status2, long status3, long status4) {
      this.uploadDateTime = uploadDateTime;
      this.status1= status1;
      this.status2= status2;
      this.status3= status3;
      this.status4= status4;
      }
  
  
  }
  </code></pre>
  
  <p><strong>EDIT-2: Added public constructor inside the class.</strong></p>
  
  <p>Best Regards,
  Famibica</p>