Spring Data JDBC を使用して OneToMany 関係をモデル化したいと考えています。この非常に便利なブログhttps://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregatesで、ToMany 参照をモデル化するときに参照を使用する必要があることを 読みました。
したがって、多対一および多対多の関係は、ID を参照するだけでモデル化する必要があります。
だから私はこのシナリオを持っています:
1つStudent
は複数を持つことができますRegistration
。そして、1 つRegistration
だけ持つことができますStudent
。Registration
割り当てられたものを削除しても、Student
カスケードは削除されません。
私はこのモデリングで終わった:
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor))
public class Registration {
private final @Id
@Wither
long registrationId;
@NotNull
private String electiveType;
@NotNull
private LocalDateTime created = LocalDateTime.now();
@NotNull
private StudentRegistrationReference studentRegistrationReference;
}
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor))
public class StudentRegistrationReference {
private long student;
private long registration;
}
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor))
public class Student {
private final @Id
@Wither
long studentId;
@NotNull
@Size(min = 4, max = 20)
private String userId;
@NotNull
@Min(0)
private int matriculationNumber;
@NotNull
@Email
private String eMail;
private Set<StudentRegistrationReference> studentRegistrationReferences = new HashSet<>();
}
私の質問は、モデリングが正しく実装されているかどうかです。