将巨大的 sql table 从逻辑上拆分成更小的 table

Split huge sql table logically into smaller tables

我正在使用 Hibernate ORM 框架制作 Spring 启动应用程序。

我有 Employee 个实体:

@Entity
public class Employee {
    private String firstName;
    private String position;

    //// more than 30 private fields

    //// fields related to one sublogic
    private String category;
    private LocalDate categoryAssignmentDate;
    private LocalDate categoryAssignmentDeadlineDate;
    private LocalDate docsSubmitDeadlineDate;
}

Employee class.

中有 30 多个私有字段

如您所见,我有 4 个字段与相同的子逻辑相关 Category

所以我的问题是:将我的 Employee 实体拆分为两个实体 EmployeeCategory 是一个好的做法,它们将连接为 OnetoOne关系?

是否让代码更清晰?

使用 embedded and embeddable 来防止双重 table 映射和不必要的 OneToOne 关系。

@Entity
public class Employee {
    private String firstName;
    private String position;

    @Embedded
    private Category category
}

@Embeddable
public class Category{
    private String category;
    private LocalDate categoryAssignmentDate;
    private LocalDate categoryAssignmentDeadlineDate;
    private LocalDate docsSubmitDeadlineDate;
}

您可能需要添加 attribute overrides