Hibernate Tutorial part 9 - Unidirectional VS Bidirectional One to One Mapping, CascadeType
www.gontu.org in this tutorial, we will learn what is the real use of a one to one mapping in hibernate along with other important concepts which we did not learn in the last tutorial i.e what is a cascadeType in hibernate, what is a Unidirectional one to one mapping and what is a Bidirectional one to one mapping.
Unidirectional vs bidirectional one to one mapping in hibernate.
www.gontu.org
Пікірлер: 59
Thanks gontu.I have searched a lot of tutorials for hibernate but no tutorial is like your tutorial. Simply awsome.
in the next tutorial, we will learn the concept of Many to one / one to Many mapping in hibernate...
@Ravikumar-gj6qw
4 жыл бұрын
Bro please uploading spring boot, microservices its urgent
I really appreciate your efforts. By following your Hibernate Tutorials i have learned a lot and its as interesting as any entertainment series. please upload more and more so that we can get quality learning. thanks
@gontuseries
10 жыл бұрын
Dhiraj Singh Hi Dhiraj Singh, thanks for liking my tutorials. many more tutorials are coming up soon in the hibernate series of tutorials. Keep visiting for updates. Happy learning.
really amazing!!before i watch ur videos i was confusing in hibernate concepts bt now i have cleared...i became your big fan..
Your tutorial is really amazing,the way you explain is crystal clear and helps me to easily get the concept,I have watched almost every video on hibernate but still no 1 explained ,which table will hold the primary key and who will hold the foreign key in OneToOne Mapping and this was really confusing for me But by watching your tutorial i learned this concept.Thanks alot, I think this is the best Hibernate tutorial on youtube , as other youtube tutors are really lagging to clear the concepts.
I seen all vedio that are great growing future of java developer ,, thanku so much sir.
your way of explanation is really very good, i understood each concept clearly...Thankyou very much for your Tutorial.
Your tutorials are great they really help me a lot! please keep posting
@gontuseries
10 жыл бұрын
thank you 25gaines. Much more tutorials in hibernate series are coming up. Happy learning.
Thanks for providing these tutorials, it's really helpful to me.., i'm also following ur spring and SpringMVC. this is the rite place for learning technologies from basic.
Dude !!!!! Awesome work bro ! I was so badly needing an explanation for the reason of the one-to-one mapping definition when it was already designed at DB level using foreign key. :D Thumbs up ! (y)
@gontuseries
9 жыл бұрын
Chandra Mohan Hi Chandra, thanks for all the appreciation :) Happy learning... many more tutorials are coming up so keep visiting for updates. Happy learning...
Great Tutorials!
Thanks a lot. very useful tutorial
I learned hibernate only through your video.After searching a lot on web. i will suggest other only your video to learn hibernate in beginning.
Great Work Bro!!!! Very useful video, I Like it
Thank you so much sir....Awesome tutorial.
Superb explanation, very good way of presenting
you are just awesome sir. Tysm It really helps me
Thanks for the help understanding CascadeType
best tutorial ,best way to learn easy from this ,Thanks sir
great job bro! keep it up!
Hi Gontuseries, Great Job! Your presentation is perfect, please continue to contribute more.
@gontuseries
10 жыл бұрын
Hi John Wesley, thank you for liking my work! Keep visiting for updates. Happy learning.
it's very helpful, #ankush , your videos are very helpful for beginners like us.
Hey, It really nice 1, helps me a lot thanks buddy :)
Excellent Video.. Thanks
perfectly explain everything nice work Thumbs up
great work
This was so good
super video bro
thank you very very very very much it helps much much much much
Thanks a lot. this tutorial is very useful.
@gontuseries
10 жыл бұрын
thank you Venkat vino... Happy learning.
gontuseries thank u for this awsome tutorial, i still have a question that is really bothering me, what if i have a parent object that is already present in database , and i want to insert a child object and associate it with the parent object that is already existring in database ? does removing "cascade" property will do the job. ? thanks in advance
Thank you
Thanks
Need Help, Well when i save child class which is one to one mapped with parent class, the insert operation works well and data is save in both tables. But when i try to delete child class, the data related to that in parent class remains while it only deletes in child class, already used CascadeType.All
think you so much
Thanks,
nice videos
Hello, In class Main you have written studentDetail.setStudent(student), if i dont write this then also it works. But reference of Student POJO class is required in StudentDetail POJO class. Can you please let me know how hibernate deals with it ?
@gontuseries
10 жыл бұрын
Hi Akhilesh Anand, in a one to one mapping case: when you say you did not write studentDetail.setStudent(student) in the code. Technically, hibernate does not impose any restriction for you to specify it always at static compilation time. But, when you run the application, if hibernate expects this line and it does not find it up there, it may throw an exception in certain cases (like attempted to assign id from null one-to-one property) or it may proceed and do the operation (which may not yield proper required output).
gr8 tutorial
Thanks for the early response. Can u plz clearly explain this annotation along with the properties used for this. @GeneratedValue(generator= "newGenerator") //name of the primary key generator @GenericGenerator(name= "newGenerator", strategy = "foreign",parameters = {@Parameter(value= "student", name = "property") })
@gontuseries
10 жыл бұрын
Hi Snoi soni, I hope this will explain it @GenericValue annotation tells what is the strategy to obtain the value for the student_id field value at runtime ( in case you do not specify any property value in it - it means use the default strategy... means hibernate is going to generate the value of student_id automatically itself) In case you specify some properties value in it - like in this case - @GeneratedValue(generator= "newGenerator") - it means you are telling hibernate: hey do not use the default strategy for generating value but use the strategy which is defined using the "newGenerator" - generator code. Now, question is where is this "newGenerator" code? answer is - just below to it you write one more annotation i.e. @GenericGenerator(name= "newGenerator", strategy = "foreign",parameters = {@Parameter(value= "student", name = "property") }) ---------------------- here you are simply defining what is "newGenerator" so you are saying here to hibernate - hey hibernate "newGenerator" is the name of the code which will provide some value as per the strategy-----> this value should be same as that of the primary key column of the student class [strategy="foreign", parameters = {@Parameter(value= "student", name = "property") }] Cheers
@nirajnayan
8 жыл бұрын
@gontuseries Good work. I am using same strategy as you defined but value in you have created for foreign key in studentdetail table as student_id is not working. it is taking null value. Please give solution .
Hi Ankush y u haven't used mapped By annotation for bidirectional... Here?????? on same thing one2many u used mapped By annotation .... Can you explain y
First Thanks a lot for this tutorial. I have a question, in the Main if we don't create a reference to the parent object (studentDetail.setStudent (student)) why we got this error ? Exception in thread "main" org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property
@dknanya
6 жыл бұрын
check this stackoverflow.com/questions/11104897/hibernate-attempted-to-assign-id-from-null-one-to-one-property-employee
so student class is inside studentDetail class, and student class is a parent table. If it is other way around, then studentDetail is the parent class? I am little confused. Thanks
Hi sir, I just sent you one mail with my issue with One to One mapping.
In bidirectional one to one mapping , how we will come to know who is parent class & who is chaild class?
@gontuseries
10 жыл бұрын
Hi snoi soni, mappings can not tell which one is a parent class and which one is a child class. These are helpful for only two purposes: navigational access (unidirectional or bidirectional) and performing mapping related tasks (e.g in the demo, using the same value of id from Master table in the child table). Now, question comes, how do we know which one is a Parent and which one is a child class in a bidirectional (or, even in a unidirectional mapping) - it may be by looking at the @GeneratedValue annotation in any of the classes: in master class (in the demo, Student class) hibernate will be generating value of student_id using some auto value generation mechanism and in the child class (in the demo, StudentDetail class) will have its value like @GeneratedValue(generator = "newGenerator") //name of the primary key generator @GenericGenerator(name = "newGenerator", strategy = "foreign",parameters = { @Parameter(value = "student", name = "property") }) point to see is strategy = "foreign" . This is one of the ways to tell which is a parent and which one is a child class in case of a one to one mapping (in both unidirectional as well as bidirectional case)
Good job ... ;-)
@gontuseries
10 жыл бұрын
Hi Michele Demundo, thanks for liking my tutorials. Many more tutorials are coming up in the hibernate series like Cache, mappedby etc etc . Keep visiting and happy learning.
No offense, but for an indian tutorial this one is really good