#14 Hibernate Tutorial | Fetch EAGER LAZY

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

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

  • @lalitchilka98
    @lalitchilka98 4 года назад +20

    To avoid StackOverFlow Exception you can comment the toString method in Alien class. Since there are 2 toSting methods ie in Alien as well as in Laptop it causes circular dependency which is basically an infinite loop. So remove the toSting method from the Alien class to avoid StackOverFlow exception.

  • @ashishbhargava632
    @ashishbhargava632 6 лет назад +6

    By default lazy is in hibernate .
    So It depends on whether you are using JPA or Hibernate.
    From the JPA 2.0 spec, the defaults are:
    OneToMany: LAZY
    ManyToOne: EAGER
    ManyToMany: LAZY
    OneToOne: EAGER
    And in hibernate, all is Lazy :)

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

    Thank you so much Navin. I have got good understanding on the basics concepts after watching your videos. Great effort. I highly appreciate your job. Please keep it up and keep us also growing.

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

    Thank you for sharing your knowledge, very nice and easy examples, direct to the point.

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

    best explanation I saw. thank you!

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

    woww thank you for sharing, Great explanation with understandable example and simple words! 👍

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

    Very neat explanation, thank you

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

    very simply explained, thank you

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

    LAZY is default only for OneToMany, for ManyToOne EAGER is default...Maybe you could've explained some operations using that too.

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

    I don't get it, every time that I run the fetch, my tables get dropped, why is that case? I followed the github example but still the tables get dropped as soon as it gets started.

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

    u are a god sir for java

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

    You are as awesome as always

  • @jatinsharma3792
    @jatinsharma3792 11 месяцев назад

    I am so much confused for the @jsonignoreproperties here If we have different tables with complex it is very difficult to understand and mapped them. Can you explain how this can be easyly to understand ?

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

    You are best Sir your videos are awesome

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

    I get a java.lang.StackOverflowError if I try to print the alien object ie if I do this syso(alien.toString()). I looked up and found that it is associated with some circular dependency. However if I try to do syso(alien.getName()) it does print the name without any Exception.

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

      I got it. There will be a circular dependency as the toString() of Laptop will call toString() of Alien and vice versa causing StackOverflow due to the infinite loop. We need to make changes in the toString() method generated by the source shortcut

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

      @@aashutoshtaikar5087 I came here to answer your question. But you already answered it LoL

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

    could you plz tell me the hibernate version which your using..compare to earlier versions, this hibernate version code implementation is so much simplified through annotations.

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

    *IMPORTANT*
    sir ,
    how could we enter values in the tables(i.e alien , laptop) because the ID column in alien and ID column in laptop, both are primary .
    then how could we insert at the same ID of alien more than one laptop.
    I am getting an error every time i am inserting more than one laptop at same alien ID.

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

      i got it...
      public class App
      {
      public static void main( String[] args )

      {
      Laptop laps1=new Laptop();
      laps1.setLid(1003);
      laps1.setBrand("mac");
      laps1.setPrice(40000);
      Alien alien=new Alien();
      alien.setAid(11);
      alien.setAname("xxx");
      alien.setColor("blue");
      alien.getLaps().add(laps1);
      laps1.setAlien(alien);
      Laptop laps2=new Laptop();
      laps2.setLid(1004);
      laps2.setBrand("dell");
      laps2.setPrice(50000);
      alien.getLaps().add(laps2);
      laps2.setAlien(alien);
      Laptop laps3=new Laptop();
      laps3.setLid(1001);
      laps3.setBrand("hp");
      laps3.setPrice(20000);
      alien.getLaps().add(laps3);
      laps3.setAlien(alien);
      Laptop laps4=new Laptop();
      laps4.setLid(1002);
      laps4.setBrand("apple");
      laps4.setPrice(90000);
      Alien alien1=new Alien();
      alien1.setAid(12);
      alien1.setAname("yyy");
      alien1.setColor("green");
      alien1.getLaps().add(laps4);
      laps4.setAlien(alien1);
      Alien alien3 = new Alien();
      alien3.setAid(1005);
      alien3.setAname("zzz");
      alien3.setColor("pink");

      Configuration con = new Configuration().configure().addAnnotatedClass(Laptop.class).addAnnotatedClass(Alien.class);

      ServiceRegistry reg = new ServiceRegistryBuilder().applySettings(con.getProperties()).buildServiceRegistry();
      SessionFactory sf=con.buildSessionFactory(reg);
      Session session = sf.openSession();
      session.beginTransaction();
      session.save(laps1);
      session.save(laps2);
      session.save(laps3);
      session.save(alien);
      session.save(laps4);
      session.save(alien1);
      session.save(alien3);

      session.getTransaction().commit();
      }
      }

  • @start1learn-n171
    @start1learn-n171 3 года назад

    TQ Naveen

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

    I like your tutorials. It will be very helpful, we you share the code also

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

    You would have also explained difference between .. get() and load() method, since they are related to Eager & Lazy terms.

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

    too good sir ji

  • @ranjitkumar-zo4se
    @ranjitkumar-zo4se 6 лет назад

    hey your classes are intresting!! Can you even explain what are microservices and a program on how to build them

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

    Hi sir, thx so much for these videos, how to print the laptop of each alien as you are printing just Navin but not the laptop correspond to it.

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

    suddenly I saw new variables and db changes before starting of this tutorial, how come..?

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

    I need to type cast in this code "Alien a1=(Alien) session.get(Alien.class,1);" whereas you have not type casted why
    If I do not type cast it gives me error why is that ??

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

      i like your tutorials and very wonderful and helpful ......................

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

      I think when we are fetching data from database it will send data in string or some other format. We need in the form of Object to use Objects. So we should do explicit casting..
      If my above statement is wrong correct me..

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

    How about fetching a certain amount?

  • @AjayGupta-md3fy
    @AjayGupta-md3fy 6 лет назад

    sir we have a lot of questions to ask please take out some time to solve our problems.

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

    Sir, please tell how you inserted data into database using OnetToMany and ManyToOne relationship ? please tell me how to insert the data into database the way you did it like for one student multiple laptops through Hibernate

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

      Hi Mayuresh have you figured out how to do it?
      I am having a problem too. In my laptop table the alien_aid is null.
      Can you look at my code and see if you can fix it please?
      public static void main( String[] args )
      {
      Laptop laptop1 = new Laptop();
      laptop1.setLid(101);
      laptop1.setBrand("Dell");
      laptop1.setPrice(1000);
      Laptop laptop2 = new Laptop();
      laptop2.setLid(102);
      laptop2.setBrand("Apple");
      laptop2.setPrice(2000);
      Laptop laptop3 = new Laptop();
      laptop3.setLid(103);
      laptop3.setBrand("Asus");
      laptop3.setPrice(800);
      Laptop laptop4 = new Laptop();
      laptop4.setLid(104);
      laptop4.setBrand("Acer");
      laptop4.setPrice(1500);
      Laptop laptop5 = new Laptop();
      laptop5.setLid(105);
      laptop5.setBrand("Samsung");
      laptop5.setPrice(1400);
      Alien alien1 = new Alien();
      alien1.setAname("Navin");
      alien1.setAid(1);
      Alien alien2 = new Alien();
      alien2.setAname("Rahul");
      alien2.setAid(2);
      Alien alien3 = new Alien();
      alien3.setAname("Mayank");
      alien3.setAid(3);
      alien1.getLaptop().add(laptop1);
      alien1.getLaptop().add(laptop3);
      alien1.getLaptop().add(laptop5);
      alien3.getLaptop().add(laptop2);
      alien3.getLaptop().add(laptop4);
      ...
      }

    • @AjayGupta-md3fy
      @AjayGupta-md3fy 6 лет назад

      did you get a response for it

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

      i have same problem bro,if you had solved this ,can you just help me please.

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

      @@I_love_mbs i got it
      public class App
      {
      public static void main( String[] args )

      {
      Laptop laps1=new Laptop();
      laps1.setLid(1003);
      laps1.setBrand("mac");
      laps1.setPrice(40000);
      Alien alien=new Alien();
      alien.setAid(11);
      alien.setAname("xxx");
      alien.setColor("blue");
      alien.getLaps().add(laps1);
      laps1.setAlien(alien);
      Laptop laps2=new Laptop();
      laps2.setLid(1004);
      laps2.setBrand("dell");
      laps2.setPrice(50000);
      alien.getLaps().add(laps2);
      laps2.setAlien(alien);
      Laptop laps3=new Laptop();
      laps3.setLid(1001);
      laps3.setBrand("hp");
      laps3.setPrice(20000);
      alien.getLaps().add(laps3);
      laps3.setAlien(alien);
      Laptop laps4=new Laptop();
      laps4.setLid(1002);
      laps4.setBrand("apple");
      laps4.setPrice(90000);
      Alien alien1=new Alien();
      alien1.setAid(12);
      alien1.setAname("yyy");
      alien1.setColor("green");
      alien1.getLaps().add(laps4);
      laps4.setAlien(alien1);
      Alien alien3 = new Alien();
      alien3.setAid(1005);
      alien3.setAname("zzz");
      alien3.setColor("pink");

      Configuration con = new Configuration().configure().addAnnotatedClass(Laptop.class).addAnnotatedClass(Alien.class);

      ServiceRegistry reg = new ServiceRegistryBuilder().applySettings(con.getProperties()).buildServiceRegistry();
      SessionFactory sf=con.buildSessionFactory(reg);
      Session session = sf.openSession();
      session.beginTransaction();
      session.save(laps1);
      session.save(laps2);
      session.save(laps3);
      session.save(alien);
      session.save(laps4);
      session.save(alien1);
      session.save(alien3);

      session.getTransaction().commit();
      }
      }

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

      i got it
      public class App
      {
      public static void main( String[] args )

      {
      Laptop laps1=new Laptop();
      laps1.setLid(1003);
      laps1.setBrand("mac");
      laps1.setPrice(40000);
      Alien alien=new Alien();
      alien.setAid(11);
      alien.setAname("xxx");
      alien.setColor("blue");
      alien.getLaps().add(laps1);
      laps1.setAlien(alien);
      Laptop laps2=new Laptop();
      laps2.setLid(1004);
      laps2.setBrand("dell");
      laps2.setPrice(50000);
      alien.getLaps().add(laps2);
      laps2.setAlien(alien);
      Laptop laps3=new Laptop();
      laps3.setLid(1001);
      laps3.setBrand("hp");
      laps3.setPrice(20000);
      alien.getLaps().add(laps3);
      laps3.setAlien(alien);
      Laptop laps4=new Laptop();
      laps4.setLid(1002);
      laps4.setBrand("apple");
      laps4.setPrice(90000);
      Alien alien1=new Alien();
      alien1.setAid(12);
      alien1.setAname("yyy");
      alien1.setColor("green");
      alien1.getLaps().add(laps4);
      laps4.setAlien(alien1);
      Alien alien3 = new Alien();
      alien3.setAid(1005);
      alien3.setAname("zzz");
      alien3.setColor("pink");
      Configuration con = new Configuration().configure().addAnnotatedClass(Laptop.class).addAnnotatedClass(Alien.class);
      ServiceRegistry reg = new ServiceRegistryBuilder().applySettings(con.getProperties()).buildServiceRegistry();
      SessionFactory sf=con.buildSessionFactory(reg);
      Session session = sf.openSession();
      session.beginTransaction();
      session.save(laps1);
      session.save(laps2);
      session.save(laps3);
      session.save(alien);
      session.save(laps4);
      session.save(alien1);
      session.save(alien3);

      session.getTransaction().commit();
      }
      }

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

    The github code is different than the video !

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

    Nice !! :)

  • @user-lw8zi7zk1i
    @user-lw8zi7zk1i 6 лет назад

    Those two who dislikes are aliens 👽

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

    What's ths

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

    Poor Rahul?? 🤣🤣