Spring Data JPA Relationships Tutorial - ManyToMany, ManyToOne & OneToMany
HTML-код
- Опубликовано: 9 фев 2021
- Learn how to use Spring Data JPA relationships such as ManyToMany, ManyToOne & OneToMany.
We create a web application using the spring starter (start.spring.io/). We then expose an API for 3 entities. We then use Spring Data JPA to create relationships between these entities.
Check out the code on GitHub here: github.com/kriscfoster/Spring...
Don't forget to Subscribe here: / @krisfoster1 - Наука
Detailed, clear and concise tutorial, hard to find such straightforward learning.
Oddly, this information was very difficult for me to find. I've been stuck trying to figure out how to configure the relationships between entities until I found this video. It was clear, concise, and best of all, my code is now working. Much appreciated Kris!
Great tutorial - short, concise, clear and with practical examples.
this is the best video explaining jpa relationships!!! Thank you soo much for sharing your knowledge :)
Thank you for the kind feedback and glad you enjoyed!
The fisrt best tutorial i have come across . It's hitting the nail on the head at the right time for me. Thannks so much teacher.
Fantastic tutorial. I was has the recursion issue and this fixed it right up! Very good tutorial with brilliant explanations. Thank you! You should do a Udemy course in Spring
I'm sharing this tutorial with all my colleagues. Amazing!
Another great spring boot video Kris.
@Ryan Hill thanks for the feedback & glad you enjoyed!
I WANNA THANK YOU A MILLION TIMES FOR THIS VIDEO. VERY VERY VERY HELPFUL !!!!!
I got my 100% of doubts cleared by this vedio. Its just crystal clear ❤️
Great video! It really helped me to create the relationships on my database. Thanks a lot!
Awesome video Kris ! It was so useful to me ! Thanks a lot !
Glad you enjoyed @Diego Ruiz, thank you for the feedback!
That was nicely explained tutorial. Thanks. Create more of this kind.
I think this is the most useful resource on spring relationships
Thank you, I needed to refeersh a bith JPA relationships and this video is very well done.
Nice ,really nice...you just got a new subscriber:)
Thanks so much. This was really great to understand the relationships
very clear and going to point easly than others
I recomend any one how wants to learn ERD in a smiple way
from that toturial
Very helpful! I was playing with JPA and kept having the infinite recursion problem with my many-to-many relations and hadn't even though the REST controllers. I watched this and fixed my backend. Great job!
That's great, nice name, Kris!
thank you so much sir this saved my life am stuck in my project for like 3 days in the many to many and u just saved me thank you dear sir
Thanks, Dude! Your tutorial helped me completed my task ))
Gracias por impartir todos tus conocimientos, al fin entendí cómo hacer relaciones con JPA.
Very decent explantion Kris....Thanks for that😊
Thank you for the feedback @Lakshmi Narayana
very useful video and well explained, thanks a lot Kris
Glad you enjoyed, thank you
Good Explanation. Keep going mate!
Thank you for the kind feedback @Raja Mani!
This helped me but I think I need a REST example but this sure helped so appreciated!
From Egypt : You are my hero with good explanation❤♥♥♥♥
It’s very helpful 🎉. Thanks
Thanks kris!! Really Helpful!!
I'm glad it helped, thank you for watching!
Kris Foster is my new Hero!
Great tutorial, thanks!!
Very helpful tutorial
Thank you, well done it was a great explanation.
Thank you, glad you enjoyed!
subbed and looking forward to more
thank you so so so so so much for this video, it helped me a lot.
short and clear, thanks
well explained kris and nice tutorial
Thank you for the feedback, glad you enjoyed!
Clear and concise.
Me salvaste, que gran aporte, saludos
thank you man , it's realy helpfull
Gold, very clear.
Thanks Bro! It's movie really good!!!
You really help me thank you ❤️
Good Material for JPA . Good job 👌
Glad you enjoyed!
Great explanation
Thank you a lot!!!
Great video 🔥
Hi Kris, your video was super helpful to fix my relationship mapping in the backend, but now I need to implement it in Angular . Would please make a video on how to implement that in Angular ?
Thank youuuuu!!
Muchas gracias me sirvio mucho tu tutorial
you are the best !!!
Thank you!
Well done brother
Thanks a lot sir
if it was a movie it can get a oscar nomination ❤️. Thank you for making us understand relationships easy. Could you please give us sample how we structure rest controller calls prod projects. Thank you
thank you!
영상 잘 봤습니다 :)
Nice One
Thank you so much for the tutorial! I was days trying to set up the relationship between my two entities, but I wasn't doing it right, so it wasn't working
thanx man
Thanks!
Hello, great video! I am curious about what happens if I do not initialize Set and leave like this 'Set students;' Can you explain me please?
Super
how to create subjects with a default teacher on post itself? Isn't it possible?
Is there a way to have a teacher assigned to the subject from inception?
@Kris Foster I have a question about the ManyToMany. If i want to add the Subject in the Student Set. How would it be? because i get an Exception when i try to save the student with the added subject.
need to do it the other way around
Came here by coincidence. Now I'm permanently here
awesome
I want to know how can we send the list of subjects in a single request using request body and how we'll assign it to student
I did everything the same but i still take an error about recursion :( I used List rather than using Set and my problem is solved. Thank you by the way. I was looking a tutorial like this. I spent all of my day on internet to learn how to create a relationship between my tables.
Thank you so much 💖
Probably you had repeated data in set. Set don't accept repeated data, but, list accept it.
Another way to solve the recursive problem is to use DTO pattern to present the retrieved data from database instead using JSON ignore!
Awesome tutorial! Now I just need to figure out how to delete students, teachers, and subjects. I get a 500 error when I try due to violating foreign key constraints.
Why not divide packages with controllers, services, repositories and models? And why use Autowired annotation instead of the better constructor injection solution?
I exactly faced the recursion issue, so your video helped a lot to understand root cause.
In case if we want to retrieve Student with subjects as well then how can we do that ?
You can just do a select statement on the subject tables.
Select * subject FROM Table_Name where student-id = 1
This is just an example so I did not use the correct names. I was to lazy to check.
The thing is what if you wanna see the subjects of one student? You would need to use the design pattern DTO (Data transfer object) right? Thats what I would do since @JsonIgnore is kind of forcing me to do so, what other solution do you recommend? Nice tutorial =)
write a select statement to retrieve the data from the join table
Hi Mate, can you demo a many to many relationship where a student is drops a subject
But how do you retrieve a one to many relationship.In this case teacher and subjects
The moral of the story is , in short need to create a customer with all dependent objects and data should get stored in the respective tables and when that customer is deleted then all the data related to that customer in the respective table should also get deleted , Thanks
thanks bro, i was have, this recursive error for 3 days, you save me. sorry for the english kkk
Bravo teacher, just i would have a link fo r the serie of this course please
Hello i understand all examples how be @OneToOne?? one object type in each Class??. Saludos desde Lima - Perú!!
Anyone know how can I getAll subjects for 1 teacher not all subjects?
Very good explatation. But I give some issue. When I use everywhere Set bettwen relationship I've got recursion problem. Replacing Set into List in Student class fix problem but I don' t konw why. Some advice ? Thanks to all.
Had the same issue, replacing one Set by a List worked for me too. Can't explain why either... but thanks for the hint! :)
@@elkamillo123 Hey, I know this is a late response, but I have spend hours researching this and I think I have the reason. Apparently it is not good practice to use Lists, as they don't perform well and they could lead to other issues. The reason we are all having this problem is due to lombok. If you remove the @data annotation, and create getters and setters , I believe you can then use the @JSONIgnore annotation, which will then allow you to stop using lists! Hope this helps!
Nice accent, nice tutorial
I really don't understand why there's so little about managing relationships when creating rest api. It's bonkers to me. What good is post and user to me, when I can't even display posts of user
Does this include entity graphs? Please answer, I don't want to waste my time.
Lindo
My name is simon :) i like
Note for myself
19:20
17:45
Why did you start from many to many relations ? It's hard for beginners to understand. Start from one to one, one to many, many to one, many to many. In this order.
finally not indian!!!!!
why are you not Indian????
Bad
Great video, I just wish you would have had an example of @Getmapping which would have returned results for a one to many with the the query:
SELECT a.name "Teacher", b.name "Subjects"
FROM TEACHER AS a
JOIN SUBJECT AS b
ON a.id=b.TEACHER_ID
And/Or a @Getmapping for the results from the many to many relationship with a filter such as:
SELECT a.name "Subject", c.name "Student"
FROM SUBJECT AS a
JOIN STUDENT_ENROLLED AS b
ON a.ID=b.SUBJECT_ID
JOIN STUDENT AS c
ON c.ID=b.STUDENT_ID
where a.name='Science'
awesome