Spring Boot | Spring Data JPA Many To Many Bidirectional Relationship Example | JavaTechie

  Рет қаралды 75,667

Java Techie

Java Techie

Күн бұрын

Пікірлер: 144
@antoniyhristov
@antoniyhristov Жыл бұрын
I've been stuck for hours not being able to create the bidirectional relationship, it was always caught from only the one end and I was going mad as to why... and it turned out it is the thing you mention at 6:28, because I was using @Data in both places. Thank you so much man, appreciate the tutorial!
@rslakshmilifestyle
@rslakshmilifestyle Жыл бұрын
Thank you so much ur comment helped me to fix my issue. 😊
@antoniyhristov
@antoniyhristov Жыл бұрын
@@rslakshmilifestyle glad it helped 🙏
@MartinGago
@MartinGago 3 ай бұрын
i was in the same situation as you, i thank you so much for this comment!
@antoniyhristov
@antoniyhristov 3 ай бұрын
@@MartinGago no worries, I am happy that I was able to help!
@yadnyeshborse5229
@yadnyeshborse5229 3 ай бұрын
Thanks For you comment , It help me solve my issue.
@pranaypaul6361
@pranaypaul6361 6 ай бұрын
Excellent video in terms of keeping it simple throughout focussing on the core basic of many to many!! One of the best out there.Thank you.
@alexgutjahr
@alexgutjahr 2 жыл бұрын
Great tutorial! Many-to-many relationships are so common in most applications. Yet I often see people struggle with setting up the relationships in the entities - they assume there has to be ONE right way of doing it, not realizing that EACH entity can own the relationship.
@Javatechie
@Javatechie 2 жыл бұрын
Agree with you
@florjandyshniku6464
@florjandyshniku6464 Жыл бұрын
@@Javatechie Great video! But if you add another student with same courses will duplicate courses. Can you solve this problem?
@g.ariywt
@g.ariywt 10 ай бұрын
Thank you for helping me understand how to use JPA and Many-to-Many relationships clearly..
@musanzawanga2083
@musanzawanga2083 2 жыл бұрын
This tutorial is a successful in explaining explain ManyToMany Relationships in Java! ✔️You made it easy to follow! ✔️Thanks alot Java Techie 💙
@roseodhiambo703
@roseodhiambo703 Жыл бұрын
I agree with you 💯.
@georgikyshenko4380
@georgikyshenko4380 Жыл бұрын
Exactly what i needed. Great job. Thanks !
@thimothipalipaka852
@thimothipalipaka852 Жыл бұрын
Hii in my project I am facing one problem, user having usercart that usercart contains products , if i add product it mapped to cart of a particular user , if add another product for same user cart it overrides the previous one how to overcome this situation .
@bluex217
@bluex217 8 ай бұрын
Thank you! I have question for 33:46: basically I'm confused that you used FetchType LAZY but yet findById method is still populating the list of courses eagerly. I have the same behavior, but I question why
@supun_sandaruwan
@supun_sandaruwan 11 ай бұрын
Great Tutorial, Thank you sir♥
@PradeepKumar-sx6ms
@PradeepKumar-sx6ms 2 жыл бұрын
In many to many directional, there are challenges in add & delete please discuss on that
@sandeeps1093
@sandeeps1093 10 ай бұрын
Its really a good aproach , Thanks Techie
@rakshitmandilwar2817
@rakshitmandilwar2817 Жыл бұрын
Java techie please help me I am getting error 415 in postman while inserting the payload.....it says the message type is not supported I tried using header as content type application json yet it doesn't work
@Javatechie
@Javatechie Жыл бұрын
Are you trying with http post method from postman
@rakshitmandilwar2817
@rakshitmandilwar2817 Жыл бұрын
@@Javatechie yes sir I am using http post method on postman for sending the data, I tried various things like using Json ignore , adding application/json in content type yet it gives error 415 and in console it gives deserialization error
@GustavoHenri777
@GustavoHenri777 5 ай бұрын
Thank you for the video.
@shubhamtopare9720
@shubhamtopare9720 2 жыл бұрын
Thanks for the informative video, one request - if you give quick summary at the end of the video i.e. what we did from start to end with the code, it will be very easy to remember the things.
@Javatechie
@Javatechie 2 жыл бұрын
Good suggestion Subham . going forward will do same
@shubhamtopare9720
@shubhamtopare9720 2 жыл бұрын
@@Javatechie Thank you.
@SumanMondal-gv8bi
@SumanMondal-gv8bi 4 ай бұрын
Thanks you so much. I am also facing stack overflow due to @Data annotation . I didn't know that. Thank You sir.
@hkkabir2024
@hkkabir2024 Жыл бұрын
good presentation but you should give all type of operations from both sides
@lovetyagi5266
@lovetyagi5266 2 жыл бұрын
when u fire find all couse student not include but we have bidrectional mapping ? so whats is the point to use @JsonBackRefrence Any Other Solution
@rekhapandit2797
@rekhapandit2797 Жыл бұрын
Thank u so much....its very helpful vedio....to understand many to many relationships.....please bring more vedios like as....also request bring the vedio on online shopping in springboot with react js...
@alparslancavdar2292
@alparslancavdar2292 Жыл бұрын
Excellence work.thx a lot
@sumithulsurkar2436
@sumithulsurkar2436 2 жыл бұрын
Thanks for sharing the valuable knowledge, but I request you to please use mice as audio of your videos is very less. Also it will be so great help if you explain few of the concepts. I mean, why we are doing this way like.
@Javatechie
@Javatechie 2 жыл бұрын
Hi Sumit i didn't get you. Is my voice is very loud 📢 or less in video?
@lemrabottabdelaziz4357
@lemrabottabdelaziz4357 2 жыл бұрын
Amazing as always !
@roseodhiambo703
@roseodhiambo703 Жыл бұрын
Thank you 🙌🙌sir.Then I have one question am confuse.the annotations @JsonManagedReference and this called MapStruct/Mapper .They do the same thing or ? am confused please help.Thank you
@mutturajdeval4841
@mutturajdeval4841 2 жыл бұрын
Great explanation 🥰🥰
@lovetyagi5266
@lovetyagi5266 2 жыл бұрын
@JSONBACKREFEENCE create problem because at a time of serialization jsonback refrence data not came in api
@Javatechie
@Javatechie 2 жыл бұрын
It shouldn't give any issue can you please share error
@kshitijbansal3672
@kshitijbansal3672 2 жыл бұрын
you are right, we cannot use @JSONBACKREFEENCE with collections, need to use @JsonIdentityInfo
@Nikhil91119
@Nikhil91119 11 ай бұрын
@@kshitijbansal3672 thanks bro
@fsdinterviewguide
@fsdinterviewguide 2 жыл бұрын
Useful video, thank you
@stefanoiacobelli2753
@stefanoiacobelli2753 5 ай бұрын
My Hero!
@ANANDKUMAR-0807
@ANANDKUMAR-0807 Жыл бұрын
Hi Basant, I have one small Doubt. In this Example fetch type is Lazy but while fetching student details, Course Details is getting Populated. I am getting Confused. Can you Please Clarify this. Thanks
@marianojm5675
@marianojm5675 Жыл бұрын
Hello, thanks for the video, but when I do that it gives me a LAZY error, I switch to EAGER and it gives me a serialization error. Why does that happen? Thank you
@Javatechie
@Javatechie Жыл бұрын
I have shared GitHub source code in video description please compare with your code and fix
@bunny96
@bunny96 Жыл бұрын
@@Javatechie , yes, you used spring.jpa.open-in-view (by default) and because of that, you didn't get a LazyInitializationException. This is an anti-pattern, btw
@omit_krish
@omit_krish Жыл бұрын
Sir here in interface we had created findByName+(Containing) but i don't know the purpose of containing key could you please let me know...
@Javatechie
@Javatechie Жыл бұрын
Do you know CONTAIN OR LIKE operator in SQL? CONTAINS is a predicate used in the WHERE clause of a Transact-SQL SELECT statement to perform SQL Server full-text search on full-text indexed columns containing character-based data types.
@omit_krish
@omit_krish Жыл бұрын
@@Javatechie got it sir thanks a bunch
@kotikobillionaire281
@kotikobillionaire281 2 жыл бұрын
I have picked up the final version from repository, and run the code as is - without any modifications. It is not working. I am getting this error when trying to add Student: Failed to evaluate Jackson deserialization for type [[simple type, class com.javatechie.entity.Student]]: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot handle managed/back reference 'defaultReference': back reference type (`java.util.Set`) not compatible with managed type (com.javatechie.entity.Student). What could be the issue?
@mitu-k4b
@mitu-k4b Жыл бұрын
Its bcz of using @JsonManagedReference and @JsonBackReference.... Did u get the solution?
@6nigam
@6nigam 2 жыл бұрын
Could make a video on jersy rest integration with swagger ui with spring boot sir.
@lightd1404
@lightd1404 Жыл бұрын
I got issues like this: when i insert new value in the table student_course_table its not update .It is just update data on table course_tbl and student_tbl. Can u help me =(((
@alelasgrutas
@alelasgrutas 2 жыл бұрын
thanks ! excellent
@YtSeshomaru
@YtSeshomaru Жыл бұрын
Maybe I'm wrong, but it seems to be bad. There's no many to many relationship if CRUD is controlled by Student entity, because there's not going to occur the same course for another student. If you delete a student, then all Courses that this Student owns will be deleted from Course entity too
@ChandlerBing11
@ChandlerBing11 2 жыл бұрын
Such a quite nice content as always. Thank you, Java Techie
@dhanshyamkamath8493
@dhanshyamkamath8493 2 жыл бұрын
Good video.
@omit_krish
@omit_krish Жыл бұрын
Sir once hit the get button i got response only student elements I'm unable to see course elements but course elements stored in course database table pls let me know.. 😊
@Javatechie
@Javatechie Жыл бұрын
What is the FetchType you have set , make it EAGER
@omit_krish
@omit_krish Жыл бұрын
@@Javatechie lazy sir
@omit_krish
@omit_krish Жыл бұрын
@@Javatechie sir after changed also getting same error only able to see student elements..
@omit_krish
@omit_krish Жыл бұрын
@@Javatechie as well posting elements while getting error like unsupported media type but i had added only json media type
@Javatechie
@Javatechie Жыл бұрын
Please check the code that I have shared and try to find out the difference
@pranabkumarnath3818
@pranabkumarnath3818 2 жыл бұрын
I have downloaded your project from github and pasted your payloads but I am getting unsupported media type error in postman . I tried writing manually also, bt same error i got. I am using sts ide, is there any problem with that?
@pranabkumarnath3818
@pranabkumarnath3818 2 жыл бұрын
I think i should learn more about serialisation and deserialisation 😂😂😂. I used @JsonIgnore and it worked.
@beytullahyayla7401
@beytullahyayla7401 Жыл бұрын
@@pranabkumarnath3818 Heyo, where did u use JsonIgnore
@sharadkumar6658
@sharadkumar6658 Жыл бұрын
Nice sir It works.
@ustemdogge4976
@ustemdogge4976 2 жыл бұрын
Hello, this tutorial is really good, i like it so much. But i have one question, how can i include some additional field in student-course table, for example to track the head of the group of students? Is there the way i can do this only with these annotations or i have to create entity for this?
@Javatechie
@Javatechie 2 жыл бұрын
No it's not possible to achieve using annotation you need to create your own entity to maintain this
@rakibulhasan1923
@rakibulhasan1923 2 жыл бұрын
when I used The @JsonManagedReference and @JsonBackReference annotations the data fetching success but did not save data. but without those annotations data saving success but not fetch data
@Javatechie
@Javatechie 2 жыл бұрын
With this annotations Post is not working? Do you mean the same
@learningjavawithme915
@learningjavawithme915 2 жыл бұрын
@@Javatechie yes
@beytullahyayla7401
@beytullahyayla7401 Жыл бұрын
Hi, did you find the answer
@Javatechie
@Javatechie Жыл бұрын
Are you also facing same issue?
@beytullahyayla5971
@beytullahyayla5971 Жыл бұрын
@@Javatechie yes
@anuraglakhara5167
@anuraglakhara5167 2 жыл бұрын
Hello sir If we want to map previously saved courses to a new student then what should we do?
@Javatechie
@Javatechie 2 жыл бұрын
Yes simply pass student with list of existing courses
@maheshmali7015
@maheshmali7015 Жыл бұрын
@@Javatechie Hello Basant Sir.. When I am trying to create new student record with existing course details, duplicate records are inserting in course table..
@Javatechie
@Javatechie Жыл бұрын
Do save and update instead of direct doing save
@yacinedrissi8811
@yacinedrissi8811 2 жыл бұрын
Hi thank you for your effort please could you do a crud operation with many to many thank you
@shubhamkale5003
@shubhamkale5003 Жыл бұрын
How can I add same course for 2 different students?
@sudheerkumar-tp1mg
@sudheerkumar-tp1mg 2 жыл бұрын
Hi Basant sir, I have one interview question, how do we maintain @transactions between 2 micro services with 2 different dbs.
@sudheerkumar-tp1mg
@sudheerkumar-tp1mg 2 жыл бұрын
One interviewer asked me, please suggest any video in our channel
@Javatechie
@Javatechie 2 жыл бұрын
You need to use saga design patterns
@sudheerkumar-tp1mg
@sudheerkumar-tp1mg 2 жыл бұрын
Thank you very much basant sir, for your quick reply.
@Javatechie
@Javatechie 2 жыл бұрын
Please check the tutorial below 👇 1. kzbin.info/www/bejne/l4DIn2RjpbZ_kMk 2. kzbin.info/www/bejne/bICYmn1thbCIntU
@samantr
@samantr 2 жыл бұрын
any enterprise application will have atleast 15-20 entities and relationships between them. In such cases what is best design - defining the relationships in entity classes or other ways ?
@sdscode
@sdscode 8 ай бұрын
Yes
@sureshmanne7245
@sureshmanne7245 Жыл бұрын
26:30 is it mandatory or neccesary that we create a new 3rd table with @ManyToMany mapping? Can we not use @ManyToMany without a 3rd table?
@sureshmanne7245
@sureshmanne7245 Жыл бұрын
Also can you tell how the methods findStudentsContainingByName & findCourseLessThanPrice fetching the data with out any JPA query written in Repository classes ?
@matheuspegorari1094
@matheuspegorari1094 Жыл бұрын
Yes it is mandatory, Many to Many relationship demands a intermediary table.
@medyazidhamlaoui2703
@medyazidhamlaoui2703 Жыл бұрын
thank you, I have a question, how can I add the course and assign the students of this course
@clipy5757
@clipy5757 7 ай бұрын
What if we want to create course separately and then want to assign them to student ?
@SandeepKumar-se2fd
@SandeepKumar-se2fd 2 жыл бұрын
Hey Basanta, Great Explanation. I have one doubt. From student api we are able to fetch both student and course data. Can we fetch course and enrolled student data from course api i.e. search/{price}??
@Javatechie
@Javatechie 2 жыл бұрын
Hi Sandeep yes we can do that
@SandeepKumar-se2fd
@SandeepKumar-se2fd 2 жыл бұрын
@@Javatechie Can you please guide, how to do?
@Iamit99yadav
@Iamit99yadav 2 жыл бұрын
Can u create same crud operation with Hibernate
@Javatechie
@Javatechie 2 жыл бұрын
We can do it easily. Instead of use EntityManager just use the hibernate session factory that's it .
@VIKASROYv
@VIKASROYv Жыл бұрын
Everything works perfectly, But there is a problem While I am trying to save only students not courses It is not able to save. Is there a work around for those scenario.
@Javatechie
@Javatechie Жыл бұрын
Can you change the cascade type and try once
@VIKASROYv
@VIKASROYv Жыл бұрын
No Luck@@Javatechie , Failed to evaluate Jackson deserialization for type [[simple type, class com.example.fts.erp.entity.Student]]: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot handle managed/back reference 'defaultReference': back reference type (`java.util.Set`) not compatible with managed type (com.gradlic.fts.erp.entity.Student)
@johnsnow1757
@johnsnow1757 2 жыл бұрын
can u tell me about put mapping
@madhusamala3921
@madhusamala3921 2 жыл бұрын
Will this code works if other student buys the same courses , it is throwing me 'detached entity passed to persist'
@Javatechie
@Javatechie 2 жыл бұрын
Please change the cascade value to persist
@mridulrajbhar12
@mridulrajbhar12 Жыл бұрын
@@Javatechie it doesn't works
@lovetyagi5266
@lovetyagi5266 2 жыл бұрын
please make video on how to create exokicit join(custom join query )with native and jpql query with and withut projection PLEASE JAVA TECHIE
@Javatechie
@Javatechie 2 жыл бұрын
Already uploaded please check kzbin.info/www/bejne/bqLLknd4eK-bbKs
@Javatechie
@Javatechie 2 жыл бұрын
Already uploaded please check kzbin.info/www/bejne/bqLLknd4eK-bbKs
@GameCrawl
@GameCrawl 9 ай бұрын
May I know where is your OneToMany tutorial?
@shutter_buggies
@shutter_buggies 5 ай бұрын
Getting stackoverlfow error how to solve this
@djv650
@djv650 2 жыл бұрын
Following the same code setup but getting this error when running: Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: Can anyone help me on this?
@RajYadav-fy4lm
@RajYadav-fy4lm 2 жыл бұрын
can we still enroll to your ongoing course or it would be too late?
@Javatechie
@Javatechie 2 жыл бұрын
Hi Raj you can enroll in the course now. Theory classes are only completed and you can also see the recording session of completed classes
@vengateshkannan3297
@vengateshkannan3297 Жыл бұрын
"status": 415, I am getting unsupported media type error in postman
@Nab-dh7bl
@Nab-dh7bl 8 ай бұрын
how did you solve it, i have the same problem thanks in advance!
@srikarthickk9708
@srikarthickk9708 6 ай бұрын
Did u fix it?
@pradeepkec
@pradeepkec 2 жыл бұрын
There will be an issue if u use mappedby in the child entity , if u delete the student, all the cource associated to students will also be deleted .
@Javatechie
@Javatechie 2 жыл бұрын
Is it let me check
@codingsunday3707
@codingsunday3707 7 ай бұрын
How can we fetch Courses that student is enrolled in ?
@Javatechie
@Javatechie 7 ай бұрын
You need to trigger join query
@itsnarahari
@itsnarahari 2 жыл бұрын
Bro I want to tell you something Today's days even If we are using Spring boot and JPA they are not using that they are using database queries only they are not allowing us to use jpa features like onetomany manytomany I didn't understand these 🤔 y they are doing like these
@Javatechie
@Javatechie 2 жыл бұрын
Usually people follow a microservice pattern where you should have a single database per service that is the reason they avoid using association mapping
@vijik2988
@vijik2988 2 жыл бұрын
Please do all mapping CRUD operation since I am facing issues with update and delete
@vibhutimaheshwari7350
@vibhutimaheshwari7350 Жыл бұрын
How is this many to many? This is rather one to many (or many to one). For one student you are saving many courses but haven't demonstrated that for one new course added to table, many students are enrolled. Also, you haven't demonstrated what happens when both santosh and basant have the same course in their enrollment list. (I tried it out and observed that two copies of the same course are getting stored instead of just one)
@Javatechie
@Javatechie Жыл бұрын
First of all this is one to many unidirectional and whatever you caught is a good point will check and update here
@vijik2988
@vijik2988 2 жыл бұрын
Can u please do update and delete operation also
@meet6712
@meet6712 2 жыл бұрын
can you please give coupon for spring data jpa course
@Javatechie
@Javatechie 2 жыл бұрын
Didn't get you @Meet
@meet6712
@meet6712 2 жыл бұрын
@@Javatechie discount coupon for your udemy course of spring data jpa
@Javatechie
@Javatechie 2 жыл бұрын
I don't have any udemy course buddy. I am giving live class on unacademy and yes coupon is available. Please reach me on javatechie4u@gmail.com for any queries
@biswajeetsahoochintu2329
@biswajeetsahoochintu2329 2 жыл бұрын
🙏🙏🙏
@channelcuriousity6467
@channelcuriousity6467 5 ай бұрын
is your name radhakanth nayak?
@amitkadam2354
@amitkadam2354 9 ай бұрын
I am very much confused with mappedBy
@knmuralimurali2922
@knmuralimurali2922 Жыл бұрын
{ "productsdetails": [ { "id": "1", "pname": "Product 1", "pquantity": "10", "punitcost": "100" }, { "id": "2", "pname": "Product 2", "pquantity": "20", "punitcost": "150" } ], "productscategory": [ { "cid": "1", "Pcategory": "Category A" }, { "cid": "2", "Pcategory": "Category B" } ], "productscolour": [ { "rid": "1", "Pcolour": "Red" }, { "rid": "2", "Pcolour": "Blue" } ] } i need to post values in json can you give me code
@sanjaykumarnayak8877
@sanjaykumarnayak8877 Жыл бұрын
Here One thing I tried is that ,after giving @JsonManagedReference and @JsonBackReference I am unable to save the data now it is saying Media type not supported, why so?
Jaidarman TOP / Жоғары лига-2023 / Жекпе-жек 1-ТУР / 1-топ
1:30:54
ВЛОГ ДИАНА В ТУРЦИИ
1:31:22
Lady Diana VLOG
Рет қаралды 1,2 МЛН
#12 Hibernate Tutorial | Mapping Relations Theory
13:14
Telusko
Рет қаралды 312 М.
The best way to map the JPA and Hibernate ManyToMany relationship
9:29
JPA / Hibernate One to Many Mapping Example with Spring Boot
20:02
Jaidarman TOP / Жоғары лига-2023 / Жекпе-жек 1-ТУР / 1-топ
1:30:54