title: What is the benefit of the NamedQuery annotation in JPA?
body: <p>Just now I wrote a <code>NamedQuery</code> for a JPA entity and was very happy about that.</p>
  
  <p>Here it is.</p>
  
  <pre><code>@NamedQuery(name=Panties.RED_PANTIES_QRY, query="SELECT p FROM Panties p WHERE p.color = red")
  public class Panties implements Serializable {
  
      public static final String RED_PANTIES_QRY = "panties.red_panties";
  
     //getters and setters
  
  }
  </code></pre>
  
  <p>With the usage</p>
  
  <pre><code>  entityManager.createNamedQuery(Panties.RED_PANTIES_QRY).getResultList();
  </code></pre>
  
  <p>One could also omit the <code>NamedQuery</code> annotation and just do</p>
  
  <pre><code>public class Panties implements Serializable {
  
          public static final String RED_PANTIES_QRY = "SELECT p FROM Panties p WHERE p.color = red";
  
         //getters and setters
  
      }
  </code></pre>
  
  <p>With the usage</p>
  
  <pre><code>entityManager.createQuery(Panties.RED_PANTIES_QRY).getResultList();
  </code></pre>
  
  <p>So the question is. What is the benefit of the first example?</p>