Home > Software engineering >  Split huge sql table logically into smaller tables
Split huge sql table logically into smaller tables

Time:11-02

I'm making a Spring boot application with Hibernate ORM framework.

I have Employee entity there:

@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;
}

There are more than 30 private fields in Employee class.

And as you can see, I have 4 fields related to same sublogic Category.

So my question is: Is it a good practise to split my Employee entity into two entities Employee and Category, which will be connected as OnetoOne relationship?

Does it make the code clearer?

CodePudding user response:

Use embedded and embeddable to prevent double table mapping and unnecessary OneToOne relations.

@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;
}

You might need to add attribute overrides

  • Related