title: SQL Error: 0, SQLState: 42703 with message "The column name str_id was not found in this ResultSet"
body: <p>this is my first question ever in StackOverflow and as suggested, I have looked at other similar questions and attempted to use their responses for my problem. So far, no luck.</p>
  <p>The situation is as follows:</p>
  <p>I have a custom query in JPA.</p>
  <pre><code>@Query(value=&quot;SELECT u.str_id,u.str_exercise_name, u.str_target_body_part,u.char_effect FROM training_schema.exercise_entity u WHERE u.str_exercise_name = ?1 and u.str_target_body_part= ?2&quot;, nativeQuery=true)
  ExerciseEntity findExerciseEntityByNameAndTargetBodyPart(String str_exercise_name,String str_target_body_part);
  </code></pre>
  <p>If I remove the name of the columns (u.str_id, u.str_exercise_name, u.str_target_body_part, u.char_effect) and replace the query with:</p>
  <pre><code>    @Query(value=&quot;SELECT u FROM training_schema.exercise_entity u WHERE u.str_exercise_name = ?1 and u.str_target_body_part= ?2&quot;, nativeQuery=true)
  ExerciseEntity findExerciseEntityByNameAndTargetBodyPart(String str_exercise_name,String str_target_body_part);
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>&quot;The column name str_id was not found in this ResultSet&quot;
  </code></pre>
  <p>The fact that the error doesn't come when I mention all the columns and is generated when I use alias 'u' doesn't make sense because this would mean that if I ever had to work with a larger table with, say, 10 columns, I would have to write them all out.</p>
  <p>One more piece of information that hopefully helps: With the version of the query where I am using 'u' instead of the column names, the error is ONLY generated when a matching record is found. For a null return from the database, there is no problem.</p>
  <p>Using Java Spring and PostgresSQL.</p>