I am currently working on a hobby project called Online School Management System where I am performing basic CRUD operations. I have limited knowledge of relationship mapping in Spring boot. There are 4 entities, student, teacher, course and classroom. I have mapped the relationship between entities accordingly. Should I include the relationship in my DTOs as well. For example: This is my course entity
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Course implements Updatable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long courseId;
private String name;
private Integer capacity;
private LocalDate startDate;
private LocalTime startTime;
@ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
private Teacher teacher;
@ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH,CascadeType.REMOVE},fetch = FetchType.LAZY)
private Set<Student> students = new HashSet<>();
@ManyToOne(cascade = CascadeType.ALL)
private Classroom classroom;
}
and This is my course DTO
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class CourseDto implements Updatable {
private Long courseId;
private String name;
private Integer capacity;
private LocalDate startDate;
private LocalTime startTime;
private TeacherDto teacher;
private Set<StudentDto> students;
}```