til icon indicating copy to clipboard operation
til copied to clipboard

Jpa + Lombok

Open raycon opened this issue 3 years ago • 1 comments

When working with JPA and Lombok, remember these rules:

  • Avoid using @EqualsAndHashCode and @Data with JPA entities
  • Always exclude lazy attributes when using @ToString
  • Don’t forget to add @NoArgsConstructor to entities with @Builder or @AllArgsConstructor.

https://dzone.com/articles/lombok-and-jpa-what-may-go-wrong

raycon avatar Nov 17 '21 10:11 raycon

@Getter
@Setter
@Entity
@NoArgsConstructor
public class Team {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Setter(AccessLevel.NONE)
  @Column(nullable = false)
  private int id;

  private String name;

  private String country;

  @Builder
  public Team(String name, String country) {
    this.name = name;
    this.country = country;
  }

}

raycon avatar Nov 17 '21 10:11 raycon