JPA 实体必须使用哪些 lombok 注释

问题描述 投票:0回答:1

JPA 实体必须使用哪些 lombok 注释,我正在考虑删除和

@AllArgsConstructor
。我应该删除
@Data
因为我正在覆盖

@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)

我需要@Data吗?

@Data: This generates equals, hashCode, and toString methods, which can cause issues with JPA. It's better to avoid this annotation for entities and define these methods manually or use other Lombok annotations selectively.

实体定义

@Slf4j
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@SuperBuilder
@Entity
@Table(name = "foos")
public class Foo extends Bar {
..
}
java jpa spring-data-jpa lombok
1个回答
0
投票

您不需要 JPA 实体的任何 Lombok 注释。

如果添加@AllArgsConstructor,您还需要@NoArgsConstructor。

你不应该覆盖@Data让它使用JVM默认值

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.