JPA / Hibernate One to Many Mapping Example with Spring Boot

In this tutorial, we will learn how to define a one-to-many unidirectional mapping between two entities using JPA and Hibernate.
Source code on my GitHub repository at github.com/RameshMF/spring-bo...
We create a Spring boot project from the scratch and we will implement the one-to-many mapping between two entities using JPA and Hibernate. We will use a MySQL database to store and retrieve the data.
The one-to-many mapping means that one row in a table is mapped to multiple rows in another table.
Read the same blog post and get the source code at www.javaguides.net/2020/04/jp....
JPA / Hibernate One to One Mapping Example with Spring Boot at • JPA / Hibernate One to...
JPA / Hibernate Many to Many Mapping Example with Spring Boot at • JPA / Hibernate Many t...
#javaguides #hibernate #springboot
Java Guides Website: www.javaguides.net/
About me: www.javaguides.net/p/about-me...
Subscribe to our KZread channel at / javaguides
Java 8 Tutorials - • Java 8 Tutorials
Spring Boot Tutorials - • Spring Boot Tutorial
Java Tutorials - • Java Tutorials
Java Best Practices - • Java Best Practices
Design Patterns in Java - • Design Patterns in Java
Servlet JSP Tutorials - • Servlet JSP Tutorials
Spring MVC Tutorials - • Spring MVC Tutorial
Hibernate 5 Tutorials - • Hibernate 5 Tutorial
MongoDB Tutorials - • MongoDB Tutorial

Пікірлер: 71

  • @JavaGuides
    @JavaGuides4 жыл бұрын

    JPA / Hibernate One to One Mapping Example with Spring Boot at kzread.info/dash/bejne/nXWNzNShk9Xej5s.html JPA / Hibernate Many to Many Mapping Example with Spring Boot at kzread.info/dash/bejne/X6Vt1NJroN3cd7g.html

  • @ravimasabattula8148

    @ravimasabattula8148

    3 жыл бұрын

    Can we have video for bidirectional one to many mapping?

  • @kaushikveluru925
    @kaushikveluru9253 жыл бұрын

    Struggled for hours and finally followed this tutorial and fixed my issue in 5 mins. Awesome tutorial. Thanks a ton for doing this!

  • @pandasofwar
    @pandasofwar3 жыл бұрын

    This is such a great tutorial! I was really struggling with a project, but this video helped me simplify my code so much. Thanks again :)

  • @pepito4
    @pepito44 жыл бұрын

    Best youtube channel for spring boot learning, I'm improving fast, thank you!

  • @drashtidesai9290
    @drashtidesai92903 жыл бұрын

    To the point information. Very useful from beginners to intermediate. Simple explanation and example that helps to understand heads-to-toe information.

  • @angelperalta6124
    @angelperalta61243 жыл бұрын

    Great explanation! Keep up the amazing work!

  • @BikerBytes
    @BikerBytes3 жыл бұрын

    Superb clear and simple instructions. Thank you sir 👍

  • @user-cs7yl8ol9l
    @user-cs7yl8ol9l3 жыл бұрын

    omg dude thank you so much, the best java channel on yt

  • @manikmahashabde2946
    @manikmahashabde29463 жыл бұрын

    Thank you so much. It helped me a lot. Glad to subscribe to your channel bro :)

  • @kirane5911
    @kirane59112 жыл бұрын

    Thank for good explanation sir, this is valuable

  • @shameel.ali.
    @shameel.ali.3 жыл бұрын

    Beautiful explanation brother

  • @umaparvathi606
    @umaparvathi6063 жыл бұрын

    Really nice sir great thanks for such a tutorial

  • @javatechnology4481
    @javatechnology44814 жыл бұрын

    It's perfect and working

  • @june3264
    @june32643 жыл бұрын

    wow! thaks! I'm Korean. Your this video is very useful me! thank you.

  • @ScienceSeekho
    @ScienceSeekho2 жыл бұрын

    Thankyou was helpful!

  • @ankitprakash8665
    @ankitprakash86653 жыл бұрын

    Thank u , this video help me alot

  • @utkarshkulkarni8178
    @utkarshkulkarni8178 Жыл бұрын

    thanks alot✨you help me alot

  • @joachimdietl6737
    @joachimdietl67373 жыл бұрын

    Nice tutorial. I wish the systems would provide them as well

  • @joes46985
    @joes469852 жыл бұрын

    Thank you sir.

  • @ryanwoodward1749
    @ryanwoodward17492 жыл бұрын

    I know this video is 2 years old but it was still very heplful!

  • @AbhinavSinghShakya2022
    @AbhinavSinghShakya20224 жыл бұрын

    Can we take some other column as referencedColumn rather than primary key

  • @radhamuthu7695
    @radhamuthu7695 Жыл бұрын

    Really good

  • @kuhugarhwal6096
    @kuhugarhwal60963 жыл бұрын

    Thanks for the video but I am still getting integrity constraint violated- parent key not found . Could you please help .

  • @mariotsck
    @mariotsck4 жыл бұрын

    Great video @java guides, I need to update 3 levels a customer his child (product) and his granchild (promotion) how can I save those 3 entities ad once?

  • @omarakki705
    @omarakki7052 жыл бұрын

    Thanks 💚

  • @urtaav639
    @urtaav6394 жыл бұрын

    Excellent content, you can make a video, where you have tables with various relationships and teach how to map them in classes, I just have a problem like that.

  • @JavaGuides

    @JavaGuides

    4 жыл бұрын

    Yes. I will plan to create a video tutorial which will cover all the mappings.

  • @jrrobles79
    @jrrobles793 жыл бұрын

    I have a question, what happens if you use the findAll() for Post it will bring you the comments?, I have this exact mapping and I can get the post a comment is in, but I can get the comments on a post, the collection always return null

  • @minisotekokie1150
    @minisotekokie11504 жыл бұрын

    Спасибо динеш)!

  • @lll-wb3vx
    @lll-wb3vx2 жыл бұрын

    thank you

  • @5kpwc14
    @5kpwc143 жыл бұрын

    Thanks for the video but I am need to know how can i implemint this mapping in my front end in angular

  • @abdelhamidtahiri9462
    @abdelhamidtahiri94623 жыл бұрын

    i have a diagram of Class i want know how i make it with jpa/hibernate(spring boot)

  • @beyondthenature
    @beyondthenature2 жыл бұрын

    Good show! make same thing with API please

  • @sakethsai3890
    @sakethsai3890 Жыл бұрын

    Bro how to perform remaining crud operations

  • @Supriya-mr2yq
    @Supriya-mr2yq2 жыл бұрын

    Is one to many and one to one bidirectional mapping can be there?

  • @prasadpetkar2841
    @prasadpetkar28412 жыл бұрын

    Good video 🤘

  • @prasadpetkar2841

    @prasadpetkar2841

    2 жыл бұрын

    Actually i want this code input from html page ,when i insert 5 records with html page they will save with their individual id and one same id for 5 records guide me with user input from web...

  • @shaileshwaghmare3
    @shaileshwaghmare33 жыл бұрын

    Great

  • @RanjithKumar-qj9mn
    @RanjithKumar-qj9mn Жыл бұрын

    How do you update comments with new one or delete one

  • @omar-boudabbous
    @omar-boudabbous Жыл бұрын

    thnx bro

  • @paulmimicry9147
    @paulmimicry91473 жыл бұрын

    Please show show to.fetch the data, fetching is more difficult that saving updating and deleting because of multiple queries it execute, iwant to show how to efficiently fetch the datas with using minimal code and/or queries.

  • @yarik83men51
    @yarik83men512 жыл бұрын

    Super

  • @christopherbryant703
    @christopherbryant703 Жыл бұрын

    How can you find all comments based on post_id?

  • @saudsiddiqui20
    @saudsiddiqui204 жыл бұрын

    Would you recommend unidirectional or bidirectional mapping

  • @JavaGuides

    @JavaGuides

    4 жыл бұрын

    It's based on the business use case and requirement. I suggest to understand both unidirectional and bidirectional mappings so that it will very easy to get real-time use cases and scenarios.

  • @satyendragupta
    @satyendragupta3 жыл бұрын

    Hi, If passible add thymeleaf + JPA / Hibernate One to Many Mapping Example with Spring Boot, like your example have one post to many comments with frontend

  • @oscargm1979
    @oscargm19793 жыл бұрын

    Bro, if i want to have 3 Entites relationed but i don´t want to delete the realationed tables.I explain myself better: i have a Entity called Screen that can have multiples list of reproduction, but if user wants to delete a Screen, i don´t want to delete lists of reproduction too, cuz it doesn´t have sense,they are totally independent(Screen and Lists of reproduction).I understand One Screen can have multiple lists of reproduction, but i don´t want the cascade,use can save a screen whenever they want and later save the list of reproduction,what cascade type is that?

  • @JavaGuides

    @JavaGuides

    3 жыл бұрын

    I suggest read this article at vladmihalcea.com/a-beginners-guide-to-jpa-and-hibernate-cascade-types/

  • @pavan3011
    @pavan30116 ай бұрын

    Referencedcolumn=I'd I'd belongs to comments right?

  • @jyotikinkarsahariacse17vel2
    @jyotikinkarsahariacse17vel23 жыл бұрын

    When I'm deleting or updating the data it is deleting from the parent table but not from the child table!!!! How to resolve this?

  • @JavaGuides

    @JavaGuides

    3 жыл бұрын

    Check cascadetype on parent class

  • @jyotikinkarsahariacse17vel2

    @jyotikinkarsahariacse17vel2

    3 жыл бұрын

    @@JavaGuides I did but it's not working!! Do we need to perform bi-directional mapping?

  • @JavaGuides

    @JavaGuides

    3 жыл бұрын

    @@jyotikinkarsahariacse17vel2 at 9:20, I have explained about cascade type and this should work. If you delete Post then along with post, it's comments should delete. Try one more solution, add orphanRemoval = true attribute to one to many annotation. stackoverflow.com/questions/2011519/jpa-onetomany-not-deleting-child

  • @JavaGuides

    @JavaGuides

    3 жыл бұрын

    Is this helped you?

  • @jyotikinkarsahariacse17vel2

    @jyotikinkarsahariacse17vel2

    3 жыл бұрын

    @@JavaGuides I'll try

  • @PradeepKumar-sx6ms
    @PradeepKumar-sx6ms3 жыл бұрын

    This example is not working in my spring boot rest controller

  • @JavaGuides

    @JavaGuides

    3 жыл бұрын

    What is the error?

  • @PradeepKumar-sx6ms

    @PradeepKumar-sx6ms

    3 жыл бұрын

    @@JavaGuides I will share the exact error. If I do only one to many its working but if I do bidirectional mapping JSON issues like Infinite loop recursion Stack Overflow issue

  • @pradeepvirtuele7160

    @pradeepvirtuele7160

    3 жыл бұрын

    @@JavaGuides Can you show me one to many bidirectional mapping in spring boot rest controller

  • @neharikakumari6636
    @neharikakumari66362 жыл бұрын

    Thoda slow kro ki pta chle itna jaldi me kyu ho aap??

  • @achyuthkodali3194
    @achyuthkodali31944 жыл бұрын

    Use lombok bro.. you will save lot of time.

  • @JavaGuides

    @JavaGuides

    4 жыл бұрын

    Good point but I do use Lombok in big projects. Using Lombok in simple example or project does not make sense and also beginners were confuse with Lombok so I don't prefer using Lombok in simple projects.

  • @achyuthkodali3194

    @achyuthkodali3194

    4 жыл бұрын

    @@JavaGuides makes sense, BTW very good video mate. Thank You.

  • @chilukabharath4809
    @chilukabharath48093 жыл бұрын

    Nice video, But... where the are the remaining crud operations 1. updating the existing comment for a post 2. delete the comment from a existing post 3.save a new comments to existing post

  • @johndoedoejohn

    @johndoedoejohn

    3 жыл бұрын

    you simply can use PostRepository in your commandLineRunner implementation method run().