title: What is the difference between adding JPA annotations to fields vs getters?
body: <p>I am new to Spring Boot and JPA in general. I've seen examples of adding JPA annotations on field declarations such as this:</p>
  
  <pre><code>@Entity
  public class Fizz {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      // other fields
  
      public Fizz(Long id) {
          super();
  
          setId(id);
      }
  
      // setter defined here
  
      public Long getId() {
          return this.id;
      }
  }
  </code></pre>
  
  <p>...as well as examples putting the same annotations on the getters like this:</p>
  
  <pre><code>@Entity
  public class Fizz {
      private Long id;
  
      // other fields
  
      public Fizz(Long id) {
          super();
  
          setId(id);
      }
  
      // setter defined here
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      public Long getId() {
          return this.id;
      }
  }
  </code></pre>
  
  <p>I'm wondering if they are semantically equivalent or if there are different use cases where you'd choose one over the other. I ask because I'm actually writing my Spring Boot/JPA app in Groovy where you typically don't define getters:</p>
  
  <pre><code>@Canonical
  @Entity
  class Fizz {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id
  }
  </code></pre>