i have a mapping problem with spring data jdbc as following:
Student
entity:
@Value(staticConstructor = "of")
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 @Wither
Set<StudentSubjectRegistration> studentSubjectRegistrations;
}
Next i have a StudentSubjectRegistration
entity:
@Value(staticConstructor = "of")
public class StudentSubjectRegistration {
@NotNull
private String electiveType;
@NotNull
private LocalDateTime created;
@NotNull
private long subjectid;
}
When i run a test to find one specific student as illustrated here:
@Test
public void findOneStudent() throws InterruptedException, ExecutionException {
long studentId = 2L;
Future<Student> student = studentService.findById(2L);
while (!student.isDone()) {
Thread.sleep(100);
}
assertThat(student.get()).isNotNull();
assertThat(student.get().getStudentId()).isEqualTo(studentId);
}
The console says that there is one sql statement issued:
Executing prepared SQL statement [SELECT student.studentid AS studentid, student.userid AS userid, student.matriculationnumber AS matriculationnumber, student.email AS email FROM student WHERE student.studentid = ?]
As for my understanding there should another sql statement be issued to fetch the associated registrations, shouldn´t it?
Instead there is an exception happening:
java.lang.IllegalStateException: Required identifier property not found for class de.thd.awp.student.StudentSubjectRegistration!
Do i have to model the StudentSubjectRegistration
with an @Id
?
StudentSubjectRegistration
should not be an aggregate root. It should be a reference from Student
where its registrations are saved.
Am i missing something?
Please note furthermore my trying to model entity immutability inspired by this blog post https://spring.io/blog/2018/09/27/what-s-new-in-spring-data-lovelace ...
Am i doing things right?
Thanks for your help!