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.
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 :)
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.
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.
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 ?
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.
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
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.
*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.
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 ??
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..
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
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); ... }
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.
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 :)
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.
Thank you for sharing your knowledge, very nice and easy examples, direct to the point.
best explanation I saw. thank you!
woww thank you for sharing, Great explanation with understandable example and simple words! 👍
Very neat explanation, thank you
very simply explained, thank you
LAZY is default only for OneToMany, for ManyToOne EAGER is default...Maybe you could've explained some operations using that too.
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.
u are a god sir for java
You are as awesome as always
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 ?
You are best Sir your videos are awesome
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.
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
@@aashutoshtaikar5087 I came here to answer your question. But you already answered it LoL
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.
*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.
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();
}
}
TQ Naveen
I like your tutorials. It will be very helpful, we you share the code also
You would have also explained difference between .. get() and load() method, since they are related to Eager & Lazy terms.
too good sir ji
hey your classes are intresting!! Can you even explain what are microservices and a program on how to build them
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.
suddenly I saw new variables and db changes before starting of this tutorial, how come..?
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 ??
i like your tutorials and very wonderful and helpful ......................
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..
How about fetching a certain amount?
sir we have a lot of questions to ask please take out some time to solve our problems.
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
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);
...
}
did you get a response for it
i have same problem bro,if you had solved this ,can you just help me please.
@@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();
}
}
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();
}
}
The github code is different than the video !
Nice !! :)
Those two who dislikes are aliens 👽
What's ths
Poor Rahul?? 🤣🤣