til
til copied to clipboard
Jpa + Lombok
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
@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;
}
}