#13. Many To Many Mapping | Practical Session

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

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

  • @saurabhkailashchandrapuran8609
    @saurabhkailashchandrapuran8609 4 года назад +2

    really appreciable sir ji ..2012 se ye sikha par aapne jis andaaj me sikhaya ...Natmastak ho gya main to prabhu

  • @manojmandil2983
    @manojmandil2983 3 года назад +16

    In the join table one entry is missing that is I'd of 2nd employee with I'd of 2nd project.
    As e1 is working on both project and on p2 project bot employee are working

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

      Yes I have the same question.. can anyone clarify.. I don't have an IT background.. so it would really help.
      Thanks in advance!!

    • @kirtiarora9588
      @kirtiarora9588 3 года назад +4

      Remove mapped by attribute from @ManyToMany annotation and it will create a new entity to map project_emp

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

      @@kirtiarora9588 so can we say that many to many mapping is lost by introducing mappedBy attribute ??

  • @sumanthkarmarkar1760
    @sumanthkarmarkar1760 Год назад +5

    The reason why single project has not been assigned to multiple employees is that, In a bidirectional relationship between two entities, it is essential to update both sides of the relationship when adding or removing entities. Here, e1 is set with list of projects, and p2 is set with list of employees, but same has to be done for e2 and p1 as well. set e2 with a project and p1 with an employee, the table is udated successfully

    • @aritradas8606
      @aritradas8606 6 месяцев назад

      What if we use cascading will it also solve the problem?

  • @mdsaif4696
    @mdsaif4696 8 месяцев назад +2

    For those commenting that project 2 is not assigned two employees. Here is the code he forgot to add.
    e1.setProjects(list2);
    e2.setProjects(new ArrayList(Arrays.asList(p2)));
    p1.setEmps(new ArrayList(Arrays.asList(e1)));
    p2.setEmps(list1);

  • @sidharthkumar6408
    @sidharthkumar6408 4 года назад +2

    Sir ke videos ka khajana khul gaya phir se. thanks sir!

  • @surajphunde1111
    @surajphunde1111 7 месяцев назад

    Thank you sir for your great teaching 😊🙏

  • @BombayAbhishekVlogs
    @BombayAbhishekVlogs 4 года назад +7

    guys tumlogo ko bhi problem aa raha hoga 1 project ek 2 employees show nhi ho raha hoga...so mapped by hata do....toh dikh jayega 1 project ke 2 employees but ek aur table create hoga mtlb 4 table

  • @codencloud
    @codencloud 2 года назад +4

    @12:44 1 Emp assigne to M Project can be seen , but 1 Project have M employees is not visible.
    Sir can u pls clarify this, thanks

  • @vivekkumarsingh1782
    @vivekkumarsingh1782 3 года назад +11

    In the joined table one emp has two projects but however one project isn't being worked by two emps. Isn't it? Explain if somebody got it.

    • @monalisapandit
      @monalisapandit Год назад +1

      Yes right I'm also confused 😕

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

      Same doubt for me also. 35 employee working on CHATBOT is not showing.

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

      I am also trying to get this. In third table there should be 3 enteries

  • @albeliever
    @albeliever 3 года назад +4

    but second project has 2 employees set, where is this info in mapped table..?

  • @Dukkibaba
    @Dukkibaba 3 года назад +5

    Sir one doubt project_2 has 2 employees e1 and e2 but in join_table we don't have entry for that, I guess one more column should have been there [e2,p2 ] correct me if I am wrong

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

      yes same doubt

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

      Remove mapped by attribute from @ManyToMany annotation and it will create a new entity to map project_emp

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

    I've Fixed the bug ... Now its working . Keep the good work going mate .. And give some jobs too :)

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

    Sir pls ek esi series b start kren project ki jis me ap koi b framework use na kren. I mean hibernate, spring ya status me se koi b na use kren framework. Lekn ek project bnayen desktop app ka jdbc k sath. Let it be student management or hospital management or whatever u like. But make sure to create it without usin framework. I want to Know how do we manually Map these relationships in jdbc and java application. I hope u get me and will soon create it Thanks. Love you :)

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

    Great !!! Thanks Bro

  • @SHIVAAY944
    @SHIVAAY944 Месяц назад

    Can we use paramaterized constructor put values in Emp e1=new Emp(11,"Ram","Hotel management"); instead of using setters to avoid code length?

  • @utkarshsaxena3511
    @utkarshsaxena3511 2 года назад +1

    sir jo project 2 ko jo humne do employess assign kiye the unki table to bani hi nhi???

  • @sajidansari-ib6cv
    @sajidansari-ib6cv 4 года назад +3

    Sir how can we fetch data from the third table?

  • @manishbolbanda9872
    @manishbolbanda9872 2 года назад +1

    empl_proj table me one employee to multiple project ka relation dikh raha hai but One project to multiple Employees wala relation nahi dikh raha haii. like emplyId 34 is assigned 2 projets but any of the projects is not done by both of them, why this happening ???

  • @rishabhsrivastava9138
    @rishabhsrivastava9138 4 года назад +4

    In many to many mapping, an employee has been assigned to multiple projects but the single project has not been assigned to multiple employees. So it will be an example of OneToMany or ManytoMany.
    Please help to clear the doubt.

    • @nshashankprasad
      @nshashankprasad 4 года назад +3

      i have same doubt. Emp_Projects should have 3 records.. kuch to gadbad hai

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

      @@kirtiarora9588 are you mad

  • @SandeepKumar-so2st
    @SandeepKumar-so2st 4 года назад +1

    Thanks

  • @adityasethi1759
    @adityasethi1759 3 года назад +3

    is there any extra setting to do ? Because upon setting the hbm2ddl = create every time table dropped first and then it create again, But you are manually dropping the Table many times... and also in logs hibernate fires the drop tables query as well and then create each table .

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

      Nope his hbm2ddl has value of update he , i think he said mistakenly that its value is create . No extra setting is required if u have create value for hbm2ddl field.

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

    Durgesh bhai getter, setter constructors k lie Lombok use kr skte ho.. generate krne ki jarurat ni padegi.. annotation se kaam ho jaega..

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

    Foreign key not created in emp table?

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

    Why do we add setters getters, a constructor with fields, and constructors without field in this video or any of your videos for that matter? please do reply to this or mention this question in any of your further videos.

    • @mayankrajput5458
      @mayankrajput5458 3 месяца назад

      Learn java basics first then come to this playlist

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

    I think p2.setEmps(list1); didn't work here. Because according to this command p2 should have been assigned to both the employees in the join table.
    Can you please clarify this sir?

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

    Thanks for the videos bhaiya. Really learning a lot from you. Jitna ho sake utna video upload kijiye during this break.
    Maine apko instagram pe msg kiya hua hai, kuch question the time mile toh dekh lijiyega. Thank you.

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

    best sir

  • @suhailbashir3389
    @suhailbashir3389 4 года назад +3

    Hi durgesh,
    Why there is no mapping entry in db for the project "Chatbot" with emp2? p2.setEmps(list1) clearly defines the many to many relationship ie. Project 2 is mapped with emp1 and emp2.Can you please check it again as there are only 2 mapping entries for emp1 only but for (pro2 -emp2) there is no entry.
    Thanks for lovely content.

    • @kaustubhchoudhary6024
      @kaustubhchoudhary6024 3 года назад +5

      Hi Suhail, according to the code Durgesh set: employee 1 --> project 1 & 2 projects and then project 2 --> emp 1 & emp 2 but he forgot to set project 1-->employee 1 and employee 2 --> project 2. Its bidirectional mapping, we need to set both to each other

    • @kirtiarora9588
      @kirtiarora9588 3 года назад +1

      Remove mapped by attribute from @ManyToMany annotation and it will create a new entity to map project_emp

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

      @@kirtiarora9588 Do we need here total 4 tables? I don`t think so..

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

    gajab ho bhai app

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

    Sir agr ap xml file mein update ki jagha create laga dein tou apko bar bar table drop krne ki zaroorat nahi padegi

  • @itzzaryanyt3101
    @itzzaryanyt3101 8 месяцев назад

    Unresolved compilation problem....... 10:33
    Type mismatch: cannot convert from org hibernate.Transaction to javax.transaction.Transaction

  • @anandlshinde
    @anandlshinde 4 года назад +4

    I have do same project . I have one doubt . as per you told one employee assign many projects . my requirement is req.1]. emp 1 assign proj. 1 and 2 req.2] emp2 assign proj.2 and 3 req.3] emp3 assign proj2 only . please guide me how to do this . Thanks In advance

    • @Manojkumar-uk6tq
      @Manojkumar-uk6tq 3 года назад +1

      create new proj. and new proj. list with only proj. to be added and then add this to emp.

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

      You need to create multiple list of project and multiple list of employee specific to each assignment in main class.

  • @RAVIRANJANKUMAR-rk1qy
    @RAVIRANJANKUMAR-rk1qy 2 года назад

    why giving null value in all table emp,project and emp_project

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

    please make a video on inheritance mapping too...

  • @albeliever
    @albeliever 3 года назад +3

    P2 should have e1 and e2 employees

    • @kirtiarora9588
      @kirtiarora9588 3 года назад +1

      Remove mapped by attribute from @ManyToMany annotation and it will create a new entity to map project_emp

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

    Exception in thread "main" org.hibernate.AnnotationException: Illegal use of mappedBy on both sides of the relationship: com.maping.Project.employees
    at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:564)

    • @srr1424
      @srr1424 8 месяцев назад +1

      How can you assign mappedBy on both sides? It can be used only on a single side.

  • @sagardarade
    @sagardarade Год назад +1

    Everything is correct here .
    Those who are complaining about e2 projects.
    Just add this 2 lines below line 45 @12:01
    e2.setProjects(projList);
    p1.setEmployees(empList);
    and everything will work as expected

    • @mdsaif4696
      @mdsaif4696 8 месяцев назад

      Why?
      it is only e1 who is assigned in two project and not e2.

  • @vineetkumar5528
    @vineetkumar5528 Год назад +1

    If you use hbm2ddl = create, it is giving FK issue in first run but not in 2nd run....
    and if you use hbm2ddl = update, no issue in first run...
    Don`t know why?? can anyone explain pls.. @Learn Code With Durgesh

    • @mayankrajput5458
      @mayankrajput5458 3 месяца назад

      yeah it can be bcz of cache problem. I am working in IntelliJ and I have to run 3 times in create mode to drop the table.😂But in update mode the program just has to update new things without erasing the older ones so that maybe the reason.

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

    thanks sir very helpful for us please start the spring frame work on project based like jsp servlet

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

    But for me everytime why this two table are creating automatic.?
    1)employee_project.
    2)project_employee.

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

      You missed it as below
      @ManyToMany(mappedBy = "projects")
      private List emps;

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

    Sir many to many web app ki video please 🙏🏻🙏🏻

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

    Sir aap ne hibernate me inheritance mapping q ni krwai 😔

  • @harshwardhanpawar4428
    @harshwardhanpawar4428 Год назад +1

    Bhai tum bade ghuma ghuma ke bata rahe ho maine jitna sikha tha usme bhi tumhara video dekh ke aur confuse ho gaya😢

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

    showing error line no: 42,43 8:46

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

    sir plz code ko likh ne ke liye ek bar pura code show kar diya karo video ke end main

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

    waiting your reply !!!

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

    Remove mappedBy Attribute

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

    Not working

    • @PT-Tl1
      @PT-Tl1 3 года назад

      I have few issues, but solved...I am pasting my code may be it can be useful to you as well...
      //Project.java
      =============
      package com.map1;
      import java.util.List;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.ManyToMany;
      @Entity
      public class Project {

      @Id
      private int pid;
      @Column(name="project_name")
      private String projectName;

      @ManyToMany(mappedBy="projects")
      private List emps;

      public int getPid() {
      return pid;
      }
      public void setPid(int pid) {
      this.pid = pid;
      }
      public String getProjectName() {
      return projectName;
      }
      public void setProjectName(String projectName) {
      this.projectName = projectName;
      }
      public List getEmps() {
      return emps;
      }
      public void setEmps(List emps) {
      this.emps = emps;
      }
      public Project() {
      super();
      this.pid = pid;
      this.projectName = projectName;
      this.emps = emps;
      }


      }

    • @PT-Tl1
      @PT-Tl1 3 года назад

      package com.map1;
      import java.util.List;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.ManyToMany;
      @Entity
      public class Emp {

      @Id
      private int eid;
      private String name;

      @ManyToMany
      private List projects;
      public int getEid() {
      return eid;
      }
      public void setEid(int eid) {
      this.eid = eid;
      }
      public String getName() {
      return name;
      }
      public void setName(String name) {
      this.name = name;
      }
      public List getProjects() {
      return projects;
      }
      public void setProjects(List projects) {
      this.projects = projects;
      }
      public Emp() {
      super();
      this.eid = eid;
      this.name = name;
      this.projects = projects;
      }



      }

    • @PT-Tl1
      @PT-Tl1 3 года назад

      package com.map1;
      import java.util.ArrayList;
      import java.util.List;
      import org.hibernate.Session;
      import org.hibernate.SessionFactory;
      import org.hibernate.Transaction;
      import org.hibernate.cfg.Configuration;
      public abstract class MappingDemo {
      public static void main(String[] args) {

      Configuration cfg = new Configuration();
      cfg.configure("hibernate.cfg.xml");
      SessionFactory factory = cfg.buildSessionFactory();

      Emp e1= new Emp();
      Emp e2 = new Emp();

      e1.setEid(34);
      e1.setName("Ram");

      e2.setEid(35);
      e2.setName("Shyam");

      Project p1=new Project();
      Project p2=new Project();

      p1.setPid(111);
      p1.setProjectName("Library Management");

      p2.setPid(222);
      p2.setProjectName("School Management");

      List list1=new ArrayList();
      List list2=new ArrayList();

      list1.add(e1);
      list1.add(e2);

      list2.add(p1);
      list2.add(p2);

      e1.setProjects(list2);
      p2.setEmps(list1);

      Session s = factory.openSession();
      Transaction tx = s.beginTransaction();

      s.save(e1);
      s.save(e2);
      s.save(p1);
      s.save(p2);

      tx.commit();
      s.close();
      factory.close();
      }
      }

    • @PT-Tl1
      @PT-Tl1 3 года назад

      com.mysql.jdbc.Driver
      jdbc:mysql://localhost:3306/demo_Project?useSSL=false
      ******
      *******
      org.hibernate.dialect.MySQL5Dialect
      create
      true

  • @LalitKumar-cw9rf
    @LalitKumar-cw9rf 3 месяца назад

    kya padata hai ye re kya padata hai.... devmanus hai ye toh

  • @Rock28099
    @Rock28099 5 месяцев назад

    What if we try to delete any project from proejct table. Then it gives error saying it exists as a foreign key in anothet table. How to handle this? If any project is deleted then all the related entries should also be deleted

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

    When I am trying to post many to many relation through postman, it throws error saying, " Resolved [org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError]". I tried different methods like not using @Data. It didn't worked. What could be solution for this error

    • @mayankrajput5458
      @mayankrajput5458 3 месяца назад

      nested objects form ho rhe hain. jab aap employee get kroge toh usme
      employee {
      project {
      employee {
      project {.......
      ...... ....}
      }
      } ese recursion honge.
      Modify your toString() method. for each entity to avoid recursions.