title: Invalid column error while using native query in JPA repository
body: <p>There are two related entities in the project.
  The trouble is in Flag field of Comment entity.
  When Flag field is present in Comment entity - the query in JPA repository fails - Error Code:</p>
  <blockquote>
  <p>17006 Message: Invalid column name.</p>
  </blockquote>
  <p>When I comment this field inside the entity (just to check)- everything works fine.
  How can I handle it properly using native queries?</p>
  <pre><code>@Entity
  @Table(name = &quot;TN_COMMENTS&quot;)
  public class Comment implements Serializable {
      
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO, generator = &quot;COMMENT_SEQ&quot;)
      @SequenceGenerator(name = &quot;COMMENT_SEQ&quot;, sequenceName = &quot;NT_COMMENT_SEQ&quot;, allocationSize = 1)
      @Column(name=&quot;ID&quot;)
      private Long id;
      
      @OneToOne
      @JoinColumn(name = &quot;TARGET_TYPE&quot;)
      private TargetType targetType;
      
      @Column(name=&quot;TARGET_ID&quot;)
      private Long targetId;
      
      @Column(name=&quot;COMMENT_BODY&quot;)
      private String commentBody;
      
      @OneToOne
      @JoinColumnsOrFormulas({
              @JoinColumnOrFormula(column = @JoinColumn(name=&quot;COMMENT_CHANGED_FLAG&quot;,referencedColumnName=&quot;FLAG_VALUE&quot;)),
              @JoinColumnOrFormula(formula = @JoinFormula(value=&quot;'COMMENT_CHANGED_FLAG'&quot;,referencedColumnName=&quot;FLAG_NAME&quot;))})
      private Flag commentType;
      
      @Column(name=&quot;COMMENT_DATE&quot;)
      private Date commentDate;
      
      @Column(name=&quot;COMMENT_USER&quot;)
      private String commentUser;
      
      @Column(name=&quot;COMMENT_USER_ROLE&quot;)
      private String commentUserRole;
      
      ...
  }
      
      
  @Entity
  @Table (name = &quot;TN_D_FLAG_DESCRIPTION&quot;)
  public class Flag implements Serializable {
  
      @EmbeddedId
      private FlagId flagId;
      
      @Column(name=&quot;FLAG_DESCRIPTION&quot;)
      private String flagDescription;
  
      public String getFlagDescription() {
          return flagDescription;
      }
  
      public void setFlagDescription(String flagDescription) {
          this.flagDescription = flagDescription;
      }
  
      public void setFlagId(FlagId flagId) {
          this.flagId = flagId;
      }
  
      public FlagId getFlagId() {
          return flagId;
      }
      
      ...
  }
  
  
  @Embeddable
  public class FlagId implements Serializable {
  
      @Column(name=&quot;FLAG_NAME&quot;)
      private String flagName;
      
      @Column(name=&quot;FLAG_VALUE&quot;)
      private Long flagValue;
      ...
  }
      
      
  public interface CommentRepository extends JpaRepository&lt;Comment, Long&gt; {
  
      @Query( value = &quot;SELECT c.* &quot; +
              &quot;FROM tn_comments c &quot; +
              &quot;JOIN tn_s_target_types t on t.code = c.target_type &quot; +
              &quot;WHERE c.target_type = ?1 AND c.target_id = ?2 &quot;,
              nativeQuery = true)
      List&lt;Comment&gt; getCommentsByTargetTypeAndTargetId(String targetType, Long targetId);
  
  }
  </code></pre>