OneToOne mapping example in Hibernate using Spring JPA | Tech Primers

Поделиться
HTML-код
  • Опубликовано: 8 ноя 2024

Комментарии • 83

  • @samuelvishesh
    @samuelvishesh 6 лет назад +2

    Your videos are really paced right and are quite detailed. You are awesome :)

  • @senkumanohar2000
    @senkumanohar2000 4 года назад +1

    simple and clear explanation..keep doing such videos

  • @9305347887
    @9305347887 5 лет назад +3

    I think duration b/w 6:55 to 7:55 ,what you said is wrong,actually if you check the hibernate sql log,it's not creating any relation b/w these two tables.Your code is working because you have same primary keys in both the tables, if you change the primary of child table i.e user_contact and have different primary key in Users table(i mean primary key of both the table should not match) in DB and then, try to delete any entries from child table i.e user_contact by passing the Id ,then it will remove the record from user_contact table and other records in users table will not be removed........But as per the @OneToOne(cascade=CascadeType.ALL) ,it should not delete the entries from child table also ....But if you maintain a separate column as a foreign key then it will not let you delete.....so i think what you told is wrong........please correct me if i am wrong....i have source code if you want to contact me then ping me at 9962790783

    • @sammy0o799
      @sammy0o799 Год назад

      Exactly , this kind of wrong informative videos make a beginner more confusion,🥴

  • @ankurpaliwal9713
    @ankurpaliwal9713 6 лет назад +2

    Thanks for this video, really liked the builder pattern you used.

  • @naturegoggle
    @naturegoggle 6 лет назад +2

    Very good explanation

  • @rahulprakash4906
    @rahulprakash4906 6 лет назад +1

    hi sir, thanks for your effort to explain one to one mapping,one gentle request from my side,can you show me how to use postMapping for posting data in both table from one controller

  • @jasper5016
    @jasper5016 4 года назад

    I wish you have covered bidirectional mapping too.

  • @rajshekharteertha7054
    @rajshekharteertha7054 5 лет назад

    please try to send request values from the json (postman). you are setting the values using setter method.

  • @sonyguptayourdearestsony
    @sonyguptayourdearestsony 3 года назад

    really this is helpful video thanks

  • @manojkalyan94
    @manojkalyan94 6 лет назад +1

    Hi Tech Primers my request is how in real time we face issues and how to solve them and how to check logs please make a video of any real time project it will really help me and I will be very thankful full to u brother

  • @praveenambati7804
    @praveenambati7804 4 года назад

    BTW, you should not worry about the primary key sequence in the JSON response. Spring JPA/Hibernate will generate id in the sequence and the end of story when spring jpa persist a record you should see your FK and PK values to be same as they are associated using OneToOne mapping.
    Query :
    SELECT * FROM USERS_CONTACT UC, USERS US
    WHERE uc.users_contact_fk = US.ID

  • @chandrashekhar-nk8zh
    @chandrashekhar-nk8zh 4 года назад

    Hi Team, how to do one to one mappings if we have multiple primary keys and also we have foreign key reference.

  • @alijenab9131
    @alijenab9131 6 лет назад +2

    thank you . it was very useful for me and i solve my problem

  • @playtochat5917
    @playtochat5917 5 лет назад

    That helped a lot.. :) Is there any chance u can do the mapping without declaring the users table id in users contact as it already exists in the Users instance which we are declaring in the users contact table...?

  • @vigneshr9903
    @vigneshr9903 7 лет назад +1

    Hai Buddy,Can u make a video tutorial for Thymelaf..please..Thanks in advance

  • @kashif3720
    @kashif3720 5 лет назад

    Can you please describe n+1 problem on this same project?

  • @sanjaykantheti4002
    @sanjaykantheti4002 5 лет назад

    Ajay , Can we write one to one mapping in users entity instead of users contact model class??

  • @manojkalyan94
    @manojkalyan94 6 лет назад +2

    Thanku so much bro u r my guru

  • @MohaideenA
    @MohaideenA 6 лет назад

    Can you write an article about Microsoft graph api integration to outlook in java

  • @rahuljadhav3231
    @rahuljadhav3231 5 лет назад +1

    Thank You Sir, this is really helpful for me.

    • @TechPrimers
      @TechPrimers  5 лет назад

      Thank you. Glad that was helpful!

  • @eamonmac2751
    @eamonmac2751 4 года назад

    i am using crud repositories and lombak and therefore i dont use constructors. does your video and method work in my case?

  • @PrabhatKumar-oj2pe
    @PrabhatKumar-oj2pe 6 лет назад

    Please check ur Git hub repo for issue reported with refernce to one-to-one papping

  • @sxb081000
    @sxb081000 4 года назад

    Hello, Im trying to implement lazy fetch type to join 2 tables based on OnetoOne Mapping to improve performance issues. I see the same performance however. Any ideas?

  • @anilnaidu4751
    @anilnaidu4751 7 лет назад +1

    hi brother nice video it is very useful for me but i have done same way but i got exception that is Field 'id' doesn't have a default value

    • @anilnaidu4751
      @anilnaidu4751 7 лет назад +1

      o.h.engine.jdbc.spi.SqlExceptionHelper : Field 'id' doesn't have a default value

    • @TechPrimers
      @TechPrimers  7 лет назад +1

      Hi Anil, Looks like the PrimaryKey (Id) is not getting auto generated. Can you check if you had added @GeneratedValue annotation which populates the Id field

    • @anilnaidu4751
      @anilnaidu4751 7 лет назад +3

      thanks for updating i solved that problem spring.jpa.hibernate.ddl-auto = update to i changed create now it is working fine

  • @venkatchittoory9981
    @venkatchittoory9981 6 лет назад

    Hi, I am getting null response, when i followed your steps. any thoughts?

  • @RohitSharma-gr9mk
    @RohitSharma-gr9mk 6 лет назад

    Hey,
    What if we have data in user table already and now we need to persist data in user contact table which is having a link to user table (same relation)
    Summary is how can I insert data into one table only while having one to one mapping.
    Please share your thoughts.

  • @ashok4harsha
    @ashok4harsha 5 лет назад

    Thanks for this video

  • @NandhuKishorReddy
    @NandhuKishorReddy 4 года назад

    difference between JPARepository vs CurdRepository please explain .thanks in advance

    • @anshulagrawal3221
      @anshulagrawal3221 3 года назад

      Difference b/w JPARepository and CRUDRepository is:-
      JPARepository is the defualt repository interface provided by Spring JPA. CRUDRepository is another interface which implements JPARepository thus providing some additional methods other than those provided by JPARepo.

  • @vipinbarman7508
    @vipinbarman7508 6 лет назад +1

    grt bhai

  • @Kaox
    @Kaox 5 лет назад

    Very fucking useful!! thank you

  • @davidewan3
    @davidewan3 6 лет назад +1

    I tried 3 classes - Class1, Class2, Class3 where Class2 had a @OneToOne to Class1, and Class 3 had a @OneToOne to Class2. First I created/saved an instance of Class1, then created a second Class1 and Class2, linked them and saved. The Ids of this second set were not shared - they were one off. When I switched to have a separate foreign key, it was correct. I'm still trying to get an example of Class1 + Class2 + Class3 all linked up working - it blows up will a null pointer error.

    • @davidewan3
      @davidewan3 6 лет назад

      I think the problem is at 7:56 of the video. You have 2 instructions for the id - auto-generate it and map it. it cant be both.

    • @Driver0077
      @Driver0077 6 лет назад

      I agree the program does not work as it seems. I was having the same problem. The @JoinColumn(name = "firstId", referencedColumnName = "meters_id")
      The firstId is not the id of the current class, it is the column you want to add to the table. if i was using the same name with the id of the class the application would not run.

    • @praveens2272
      @praveens2272 2 года назад

      That's the problem with JPA and Hibernate. If the database has multiple relationships with multiple tables, it sucks. Spring JDBC is the best option.

  • @armanreyaz1956
    @armanreyaz1956 4 года назад

    When I am using GerationType.AUTO for id, ids generating in tables are not from 0 but sequence wise. if the first table has last id 5 than the new table will save starting id 6. Please help.

  • @kishoremaroju2720
    @kishoremaroju2720 6 лет назад

    Hi Brother, I am a good follower of all your tutorials, nice work.
    Could you please make a video on
    Spring data jpa with Cassandra database.
    Thanks.

  • @vidyesh1502
    @vidyesh1502 5 лет назад +2

    i went for an spring interview where hr ask me a question
    write entity by which u can enter same data in 2 tables and if u update data it will enter only into the 2nd table.so if new data comes it will enter in same table and onky updated data into 2nd table.
    how to do that?

    • @TechPrimers
      @TechPrimers  5 лет назад +1

      You can google it out. I have seen solution in stackoverflow

    • @vidyesh1502
      @vidyesh1502 5 лет назад

      yes sir, i use abstract class n extend it 2 entities n then i write 1 repository n set its value to another repository. so i can ene same data into 2 tables

    • @vidyesh1502
      @vidyesh1502 5 лет назад

      im fresher interview told me if u solve this task i will give u job offer.. i hope i will get job 😃

    • @vidyesh1502
      @vidyesh1502 5 лет назад +1

      is there any other way to do this other than abstract class? plz told me if u know.. cz i think interviewer expected some other way to do this..☺️ he was asking me about mapping in entity class..
      and good news is i got job offer..😃

  • @mukultaneja8014
    @mukultaneja8014 7 лет назад

    how can we do it by post method using JSON?

  • @jasper5016
    @jasper5016 4 года назад

    Why files in your github repo are removed? I cannot find updated Users.java and UserContact.java.

  • @mdriyyan
    @mdriyyan 6 лет назад +1

    Hi Tech Primers, I Follow Your Videos, They are Really Helpful,
    CAN YOU DO A POST METHOD Using JSON,
    Thanks In Advance

    • @TechPrimers
      @TechPrimers  6 лет назад

      sure Mohammed. Will do it tomorrow.

    • @mdriyyan
      @mdriyyan 6 лет назад

      Is It Possible For You to Do it for OnetoMany and ManyToMany ALSO,
      Thank You So Much

    • @asrarooman7289
      @asrarooman7289 6 лет назад

      Thank You For The Informative Videos TECH PRIMERS, Waiting for POST METHOD using Json

    • @TechPrimers
      @TechPrimers  6 лет назад

      Hi Mohammed, I have done both already. Check out the "Hibernate playlist", also i have created the POST method video. Take a look

    • @TechPrimers
      @TechPrimers  6 лет назад

      POST video is done. here you go: ruclips.net/video/nhH1PQF1698/видео.html

  • @RamGopalsubbu10
    @RamGopalsubbu10 5 лет назад +1

    Whenever I do an entry in db the child object is getting +1 id value to that of its parents. Ex:
    {
    "id": 1,
    "name": "Batman",
    "details": {
    "id": 2. // increment value of parent
    "team": "DC"
    }
    }
    I followed each and every step. What could be wrong?

    • @SubhSingh
      @SubhSingh 5 лет назад

      I am also facing exactly same issue.... :(

    • @SubhSingh
      @SubhSingh 5 лет назад +1

      You can fix it by providing GenerationType.IDENTITY for ID.

    • @ajmndilhan7153
      @ajmndilhan7153 4 года назад

      @@SubhSingh i got the same issue but your solution solved it,. Thank you very much

  • @techappleteja8564
    @techappleteja8564 4 года назад

    Okay I get that using get to make this simple tut

  • @FuadHussainrocz
    @FuadHussainrocz 6 лет назад

    i have a simple question. there is no dependency for hibernate in your pom.xml. does spring jpa use hibernate for implementation by default. reply plz its really confusing me

  • @rajeshch1267
    @rajeshch1267 5 лет назад

    how to fetch the data from multiples tables and how perform joins in spring data jpa

    • @rajeshch1267
      @rajeshch1267 5 лет назад

      please replay any body

    • @TechPrimers
      @TechPrimers  5 лет назад

      you can use @OneToOne, @OneToMany or @ManyToOne mappings via jpa

    • @rajeshch1267
      @rajeshch1267 5 лет назад

      can we possible with out relationship.i thanking in repository create custom method and on top of the method add @Query annotations inside pass directly join query without relationship. Is it possible

  • @7mssrinivas
    @7mssrinivas 5 лет назад

    im getting output like this can you please tell the what will be the error.....o/p-- {
    "id": 1,
    "phoneNo": 111111,
    "value": {
    "name": "srinivas",
    "salary": 30000,
    "teamName": "JBHUNT",
    "id": 2
    }
    }

  • @yashmishra1024
    @yashmishra1024 4 года назад

    It's not working, throws null pointer exception.

  • @srinathnirmal867
    @srinathnirmal867 6 лет назад

    hi bro manytomany relationship video link share me.

  • @feelit_nursing_acadamy
    @feelit_nursing_acadamy 3 года назад

    can you sent me previous video

  • @pranavpatil8072
    @pranavpatil8072 7 лет назад +1

    Hi There! watching for the first time and i liked it, Nice video!
    When i try to run my Spring boot app i have no issues inserting the data i DB, but when i try to retrieve the data it only the UserContact gets displayed..
    {
    "id": 1,
    "phoneNumber": "4699553435",
    "user": null
    }
    my userContact respository does nothing special
    public List getUserContact() {
    return userContactRespository.findAll();
    }
    Any suggestions would be appreciated!

    • @TechPrimers
      @TechPrimers  7 лет назад

      Can u check if your Enity with user object does EAGER loading rather than lazy loading?

    • @pranavpatil8072
      @pranavpatil8072 7 лет назад +2

      Thanks bud! I was using one to one mapping and i believe its eager by default, any ways i resolved the issue! Thank you! Subscribed :)

    • @TechPrimers
      @TechPrimers  7 лет назад +1

      +Pranav Patil cool

  • @akashbhaskar3816
    @akashbhaskar3816 4 года назад

    I am getting 2 records in both the table after i hit "localhost:8080/rest/usercontact/update/abc" anyone facing the same issue?
    on the console i am getting :
    Hibernate: insert into user (name, salary, team_name) values (?, ?, ?)
    Hibernate: insert into user_contact (contact_num) values (?)
    Hibernate: insert into user (name, salary, team_name) values (?, ?, ?)
    Hibernate: insert into user_contact (contact_num) values (?)

  • @nirmalmohanty7852
    @nirmalmohanty7852 5 лет назад

    I followed the exact steps but for me the ids are not getting mapped. Here is the response:
    [
    {
    "id": 1,
    "phoneNo": 1111,
    "users": {
    "id": 2,
    "name": “name”,
    "teamName": “teamname”,
    "salary": 1000
    }
    }
    ]

    • @7mssrinivas
      @7mssrinivas 5 лет назад

      hello nirmal mohanty..i'm also getting same output did you find the soultion for that!

    • @nirmalmohanty7852
      @nirmalmohanty7852 5 лет назад

      @@7mssrinivas No, not yet.

    • @7mssrinivas
      @7mssrinivas 5 лет назад

      @@nirmalmohanty7852 ok but i got it... Change the autogeneration to identify... It is in auto so once change it check it its working for me..