spring-bootspring-data-jpa

Spring JPA filtration and setting


New to java development. Using Spring Boot and Spring JPA to develop a web app.

We have the following data model.

Student - ID, Name, Grade Course - ID, Name StudentCourse - ID, StudentID, CourseID, StartDate, Status StudentAttendance - ID, StudentID, CourseDate, AttendaanceDate, Status StudentCourseGrade - ID, StudentID, Attempt, CompletionDate, Grade

There are a few more tables as well. All the tables will have StudentID as the referential key.

Have created JPA repository for all the tables. We use single sign on for the student logon. Hence the StudentID will be available in the context. After logon, the student should query only his own data. For example, when the student queries the courses (StudentCourse), he should be able to view only his own courses. Also, when a student joins a new course (StudentCourse), the StudentID should be automatically applied. This is applicable to all tables containing StudentID. What is the best way to implement this in a generic way for all the tables containing StudentID? Pointers to documentation will also be helpful. Thanks in advance.


Solution

  • Have used hibernate @FilterDef and @Filter to achieve this.