JPA / Hibernate One to Many Mapping Example with Spring Boot

Sdílet
Vložit
  • čas přidán 24. 07. 2024
  • 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 CZcams 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

Komentáře • 71

  • @JavaGuides
    @JavaGuides  Před 4 lety +5

    JPA / Hibernate One to One Mapping Example with Spring Boot at czcams.com/video/kAYjrhcrx_8/video.html
    JPA / Hibernate Many to Many Mapping Example with Spring Boot at czcams.com/video/-q9rp2pzvGU/video.html

  • @utkarshkulkarni8178
    @utkarshkulkarni8178 Před rokem

    thanks alot✨you help me alot

  • @omarakki705
    @omarakki705 Před 2 lety

    Thanks 💚

  • @lll-wb3vx
    @lll-wb3vx Před 2 lety

    thank you

  • @radhamuthu7695
    @radhamuthu7695 Před rokem

    Really good

  • @omar-boudabbous
    @omar-boudabbous Před rokem

    thnx bro

  • @yarik83men51
    @yarik83men51 Před 2 lety

    Super

  • @prasadpetkar2841
    @prasadpetkar2841 Před 2 lety

    Good video 🤘

    • @prasadpetkar2841
      @prasadpetkar2841 Před 2 lety

      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...

  • @kaushikveluru925
    @kaushikveluru925 Před 3 lety +5

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

  • @pandasofwar
    @pandasofwar Před 3 lety +5

    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 :)

  • @ankitprakash8665
    @ankitprakash8665 Před 3 lety

    Thank u , this video help me alot

  • @ScienceSeekho
    @ScienceSeekho Před 2 lety

    Thankyou was helpful!

  • @joes46985
    @joes46985 Před 2 lety

    Thank you sir.

  • @pepito4
    @pepito4 Před 4 lety +1

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

  • @javatechnology4481
    @javatechnology4481 Před 4 lety

    It's perfect and working

  • @drashtidesai9290
    @drashtidesai9290 Před 3 lety

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

  • @june3264
    @june3264 Před 3 lety

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

  • @BikerBytes
    @BikerBytes Před 3 lety +1

    Superb clear and simple instructions. Thank you sir 👍

  • @kirane5911
    @kirane5911 Před 2 lety

    Thank for good explanation sir, this is valuable

  • @angelperalta6124
    @angelperalta6124 Před 3 lety

    Great explanation! Keep up the amazing work!

  • @umaparvathi606
    @umaparvathi606 Před 3 lety

    Really nice sir great thanks for such a tutorial

  • @ryanwoodward1749
    @ryanwoodward1749 Před 2 lety

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

  • @user-cs7yl8ol9l
    @user-cs7yl8ol9l Před 3 lety

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

  • @shameel.ali.
    @shameel.ali. Před 3 lety

    Beautiful explanation brother

  • @manikmahashabde2946
    @manikmahashabde2946 Před 3 lety

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

  • @sakethsai3890
    @sakethsai3890 Před rokem

    Bro how to perform remaining crud operations

  • @urtaav639
    @urtaav639 Před 4 lety +1

    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  Před 4 lety +2

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

  • @joachimdietl6737
    @joachimdietl6737 Před 3 lety

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

  • @kuhugarhwal6096
    @kuhugarhwal6096 Před 3 lety

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

  • @paulmimicry9147
    @paulmimicry9147 Před 3 lety +1

    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.

  • @mariotsck
    @mariotsck Před 4 lety

    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?

  • @AbhinavSinghShakya2022

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

  • @shaileshwaghmare3
    @shaileshwaghmare3 Před 3 lety +1

    Great

  • @5kpwc14
    @5kpwc14 Před 3 lety

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

  • @pavan3011
    @pavan3011 Před 6 měsíci

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

  • @christopherbryant703
    @christopherbryant703 Před rokem

    How can you find all comments based on post_id?

  • @minisotekokie1150
    @minisotekokie1150 Před 4 lety

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

  • @RanjithKumar-qj9mn
    @RanjithKumar-qj9mn Před rokem

    How do you update comments with new one or delete one

  • @abdelhamidtahiri9462
    @abdelhamidtahiri9462 Před 3 lety

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

  • @beyondthenature
    @beyondthenature Před 2 lety

    Good show! make same thing with API please

  • @jrrobles79
    @jrrobles79 Před 3 lety

    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

  • @satyendragupta
    @satyendragupta Před 3 lety

    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

  • @PradeepKumar-sx6ms
    @PradeepKumar-sx6ms Před 3 lety

    This example is not working in my spring boot rest controller

    • @JavaGuides
      @JavaGuides  Před 3 lety

      What is the error?

    • @PradeepKumar-sx6ms
      @PradeepKumar-sx6ms Před 3 lety

      @@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 Před 3 lety

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

  • @oscargm1979
    @oscargm1979 Před 3 lety

    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  Před 3 lety +1

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

  • @saudsiddiqui20
    @saudsiddiqui20 Před 4 lety

    Would you recommend unidirectional or bidirectional mapping

    • @JavaGuides
      @JavaGuides  Před 4 lety

      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.

  • @Supriya-mr2yq
    @Supriya-mr2yq Před 2 lety

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

  • @jyotikinkarsahariacse17vel2

    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  Před 3 lety

      Check cascadetype on parent class

    • @jyotikinkarsahariacse17vel2
      @jyotikinkarsahariacse17vel2 Před 3 lety

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

    • @JavaGuides
      @JavaGuides  Před 3 lety +1

      @@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  Před 3 lety

      Is this helped you?

    • @jyotikinkarsahariacse17vel2
      @jyotikinkarsahariacse17vel2 Před 3 lety

      @@JavaGuides I'll try

  • @achyuthkodali3194
    @achyuthkodali3194 Před 4 lety

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

    • @JavaGuides
      @JavaGuides  Před 4 lety +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 Před 4 lety

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

  • @chilukabharath4809
    @chilukabharath4809 Před 3 lety

    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 Před 3 lety

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

  • @neharikakumari6636
    @neharikakumari6636 Před 2 lety

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