Skip to content
Advertisement

Fetch list of forms that are belong to a specific student

I have a class of Form and Student. A student may have 0 or many forms. I set the relation between them as OneToMany. Now, I need to fetch the forms that are owned by a specific student. I have two questions at that point. How should I fetch those forms in the URL? Let’s say I want to fetch the forms of the student with id=7.

Option 1:

JavaScript

Option 2:

JavaScript

Which one of them is most used or more reasonable? The second problem is that. Normally, when I want to add a new method to the JpaRepo. I just need to add the method that is served by Jpa such that findAll, findByStudentId. Since I have a list of forms in the Student entity/model. How can I fetch all the forms? Which named method should I use? To sum up, I need to know whether I should write the method in FormDataAccess or StudentDataAccess. And what should be the method name?

Student

JavaScript

Form Model

JavaScript

Advertisement

Answer

The solution is really simple.

I just need to write a query in my FormDataAccess.

JavaScript

now I can retrieve the forms using this path

JavaScript

I still wonder how to retrieve the forms from the Student side, not Form side such that

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement