title: javax.persistence Annotations on field, getter or setter?
body: <p>I am currently learning Hibernate and the Java Persistence API.</p>
  
  <p>I have an @Entity class, and need to apply annotations to the various fields. I have included in the code below all three places where they could go.</p>
  
  <p>Should I apply them to the field itself, the getter or the setter? And what is the semantic difference, if any, between these three options.</p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.Table;
  import javax.persistence.Id;
  
  @Entity
  @Table(name = "song")
  public class Song { 
      // Annotations should only be applied to one of the below
  
      @Id 
      @Column(name="id", unique=true, nullable=false)
      private int    id;
  
      @Id
      @Column(name="id", unique=true, nullable=false)
      public int getId() {
          return id;
      }
  
      @Id
      @Column(name="id", unique=true, nullable=false)
      public void setId(int id) {
          this.id = id;
      }
  }
  </code></pre>