title: Spring Boot JPA how to select specific column from table with the entity class?
body: <p>In am using spring boot JPA for my database operations. In my entity class, I mapped every columns with my table. In my table I have many columns, but I need to select some of them in my query result set. I does not need to do <code>select * from table_name</code> which brings the performance issue to my application.</p>
  
  <p>My entity class:</p>
  
  <pre><code>@Entity
  @Table(name = "user_table")
  public class UserInformation {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "user_id")
      private int userId;
  
      @Column(name = "user_name")
      private String userName;
  
      @Column(name = "user_type")
      private String userType;
  
      @Column(name = "user_age")
      private int userAge;
  
      @Column(name = "is_male")
      private boolean isMale;
  }
  </code></pre>
  
  <p>After this I generated all getters and setters for above class.</p>
  
  <p>My userDAO class</p>
  
  <pre><code>public interface UserInformationRepo extends 
           JpaRepository&lt;UserInformation, String&gt;{
  
      @Query(value="select user_name from user_table where user_age &gt; 
                 :userAge", nativeQuery=true)
      public UserInformation getInfo(int userAge);\
  
      @Query(value="select user_name,userType, user_id  from user_table where 
            user_age &gt; :userAge", nativeQuery=true)
      public UserInformation getInfo(int userAge);
  }
  </code></pre>
  
  <p>When I run this spring boot app with my above class it shows error as </p>
  
  <blockquote>
    <p>user_id was not included in the ResultSet</p>
  </blockquote>
  
  <p>This error because I did't select the user_id from my query.</p>
  
  <p>In my userDAO class I have a multiple functions, each functions need different set of columns, but the return type of all methods should be UserInformation class.</p>
  
  <p>My excepted result is, the columns which I does not select from query should have null value in my result UserInformation object.</p>
  
  <p>I also searched many resources for this, but I cannot find any relevant answer.</p>
  
  <p>Any Help. Thanks in advance</p>