Это видео недоступно.
Сожалеем об этом.
#13 Hibernate Tutorial | Mapping Relations Practical
HTML-код
- Опубликовано: 18 янв 2017
- Hibernate is ORM i.e. Object relational mapping tool.
Hibernate mapping relations are:
@Many-to-One
@One-to-One
@One-toMany
@Many-to-Many
Trainer: Navin Reddy
Github :- github.com/nav...
Check out our website: www.telusko.com
Follow Telusko on Twitter: / navinreddy20
Follow on Facebook:
Telusko : / teluskolearnings
Navin Reddy : / navintelusko
Follow Navin Reddy on Instagram: / navinreddy20
Subscribe to our other channel:
Navin Reddy : / @navinreddy
Telusko Hindi :
/ @teluskohindi
Subscribe to the channel and learn Programming in easy way.
Java Tutorial for Beginners : goo.gl/p10QfB
Scala Tutorials for Java Developers : goo.gl/8H1aE5
C Tutorial Playlist : goo.gl/8v92pu
Android Tutorial for Beginners Playlist : goo.gl/MzlIUJ
XML Tutorial : goo.gl/Eo79do
Design Patterns in Java : goo.gl/Kd2MWE
Socket Programming in Java : goo.gl/jlMEbg
Spring MVC Tutorial : goo.gl/9ubbG2
OpenShift Tutorial for Beginners : goo.gl/s58BQH
Spring Framework with Maven : goo.gl/MaEluO
Sql Tutorial for Beginners : goo.gl/x3PrTg
String Handling in Java : goo.gl/zUdPwa
Array in Java : goo.gl/uXTaUy
Java Servlet : goo.gl/R5nHp8
Exception Handling in Java : goo.gl/N4NbAW
0:00: Intro
2:04: OneToOne
4:42: OneToMany
8:23: ManyToOne
11:12: ManyToMany
in Eclipse mars version press Alt+shift+R to change the variable or object name at once.
Eclipse version doesn't matter..this shortcut works with all versions of eclipse.
Hi Navin Sir, to replace any word in eclipse .. just select it.. press control +1.. and rename.. save
Thank you for your "education" Navin! I'm really learning from your videos. Keep the good work.
for refractor to variable on Windows u can use
alt+shift+R
and also select the variable that you want to change. for Mac u can search how u can get it
You can change 's' to 'student' in one go if you select the 's', right click and refactor->rename. This changes 's' to 'student' in the same class.
Hi , to change the name once using eclipse, you can right click on that reference variable , right click ->select refactor ->-select Rename ->change the value as expected .
bro, please make one video for how to save image files into database and how to retrieve image files from database
i took whole day to understand mappings from different sources.. was still not clear concept.. saw this 15 mins video, now its crystal clear.
Thanks a lot. This mapping thing was bugging me a lot. I have seen so many videos but only you were able to clear all my doubts. Thanks again.
Hello Navin Sir, you should use Alt+Shift+R for replacing all the occurence on an objectName in any version of eclipse.
Your onetomany example will not work, when I'm setting student.getLaptops().add(laptop), no data is updated in laptop table for student.
But if I do, laptop.setStudent(student) then its working fine.
Please let me know, If I'm correct ?
I think you're right. Also you need to persist student before laptop.
Its quite common that , you need to save the student_id (foreign key) in laptop table. So obviously you need use laptop.setStudent(StudentObj)
No. It's not required. It will update it automatically. It will first search the student table with the given student_rollNo. If available it will inserts laptop straight forward. Otherwise, It will first insert the laptop and then the student. And after inserting student, It will update laptop with that student_rollNo value from student table. You can try and see the hibernate query for reference.
So then why not it happened to us , (student id not save in laptop table unless you persist it as laptop.setStudent(StudentObj) )? Can you explain it and any possible reason
@@niranjanmaharana9089 then why im getting null reference in laptop table
This is best explanation and implementation of mappings. Thanks a lot.
Your videos are flashing!!! My eyes have all fallen out...
shift F6 and press enter ,you can add newname and it will add everywhere
it's refactoring.. It's in eclipse. select and right click and select refactor.. everything will be chnaged
I learnt from your videos many things sir !!!Thanks lot
You may use refractor in eclipse
Such a great explanation Sir. Thank you.
Thanks for clear explanation. I would like to know the update part in ManyToOne relationship. Say you have student with Dell and Mac today and tomorrow he got Dell And Sony. Here it should delete Mac and relate new Sony.
thank you telusko...It saved my life..nice work...
Thank You For Making My Fundamentals Clear.
Double click on s and then select refactor and type what ever u need , then name changes in all the places in editor
In Intellij, I press SHIFT + F6 to rename a variable
You can use Alt+Shift+R in eclipse to change the variable name in all the places in that method.
Navin in Eclipse we use refactor to references of variable and methods as class also. (Alt + shift + r) is shortcut to use refactor.
Alt+Shift+r
to change name of variables
pls show one example with auto increment applied for both laptop id and student id. getting "foreign key constraint". I have also gone through sql query. there is error in it.
I love you man, your tutorials are very very good.
3.26 min, use Alt+Shift+R then you can rename the object and all the recurrences will be changed automatically
Thanks a lot for this helpful video
Excellent Stuff
you can do ctrl+f and replace all.....not depending on the eclipse shortcuts
Thank you so much sir all my doubts have been clear.
Sir can you please create a vedio on how map struct works in jpa.
you just earned a new sub man!
While using OneToMany and ManyToOne..the foreign key column being included in the table always having NULL value... How do I resolve that?
Hey navin, i love the way you explain tge things.. I have seen so many videos of yours and it helped me lot to grow technically.
And u wanna know hw to rename a variable so that it rename all its references. So it is possible with Eclipse use Ctrl+Shift+1 and it will give you option, u have to choose first and then rename wherever u want.
Great explained, thanks.
many to one means that laptop 1 can be associated to student1 and student2. This means that we will have two records with laptop1 but if the mapping is done by laptop this wouldnt be possible. Any thoughts?
i want to raise that question as well
but i think in that case we need the third table so it can be possible
how does birectional works for these mappings
How to define mappedBy and @JoinColumn in different classes.. there is lot of confusion reg. this.. can you pls explain this and let me know the video link
for new version refactor option is available
refactor -> rename (alt + shift + r)
Thank You very much... it helped me a lot...
i got confused, if it is a one to many relationship, one student can have multiple laptops. the student table must have the laptopID column otherwise it is not possible to create a relationship where one student can have multiple laptops. Why do we end adding a studentID column in the laptop table?
Excellent and help ful
Very nice demo on Hibernate relationship. Can you please make one video on @OneToMany unidirectional vs bidirectional explaining how they differ ?
If we just persist parent object, it must force updates on child object as well. Can you post some video on best practices to achieve that. Currently, my parent-child update is very slow because internally it selects and then deletes from child table, then inserts new/updated data into child table [impacts performance]. How to deal with this?
cool. know mappedBy so clearly, thnaks pro
Can you explain @joincolumn also?
Really good explation
Hey Navin, many thanks for doing this. In the same example, could you please tell me how to set the date in case of onetomany relationship?
do u have a github repository for these examples
Nice and clear, thaaaanks!
Can we do that by not hardcoding ids?
pls show for multiple entries.
Great job, keep working
Thank you for a Great video!
Do you know how to handle hibernate @inheritance? If you do, would be great if you could add another video for this topic.
I have a doubt about in fetching data from two tables using manytomany
Please Give Example with ManytoMany Relation with spring MVC. It will be helpfull for us. There are no example spring hibernate ManytoMany annotation
Hi, could you please upload videos for bidirectional mapping as well.. which is really more important too..!
very good thank you but what if the table laptop_student have some attribute how we can do ?
cloud u tell me pls u have any video ! how to connect MySQL workbench to eclipse? i am searching ur list but not found.
Awesome series, could you please explain about FetchType Lazy, Eager and CasCadeType all annotations please ?
I have a question sir..
Suppose i have 2 students let's say navin and reddy , and 2 laptops hp and dell
can i put entry in laptop_student table like this {navin hp} and {navin dell} without creating another class of laptop_student in eclipse?
please explain
Sir I did same with Employee and Computer class. But in my Customer database the emp_id is all null
Sir in the case of manytomany when i entered 2 entry let say a single laptop which is available for 2 students this is throwing an error because we can't store two time same laptop in laptop table....how can i manage this error???
Excelleny and helpful
Hello Sir, I have a query please solve it..I am using OneToOne annotation. If i dont make primary key auto generate. And i will set 1st person id = 1 and pdetailId = 1 and then save this data with using save(1stperson). And then again i save 2nd person id = 2 but keep pdetailId = 1 then also it is saving data which makes Many to one mapping. Can u help me to solve my thinking on this why this is happening?
For rename you can just rename the reference by 'refactor' it or just 'Alt+Shit+R'
thank you sir , if we use to-string method in both the classes, ie student and laptop class , and then if we save and run the program it shows stack overflow error in the console screen, can i know why
in intellij shift+F6 to change the variable.
u'r the best
May be too late to ask now but please help me in understanding when the laptop instance has a student field (Many to one), noticed that student list is set with laptop and we left the student field in laptop although if done sounds like circular but please let me know.
Alt+Shift+R in eclipse. Using Oxygen.
Good tutorial
Hello sir, in one to many : In laptop table rollnumber column is printing nulll.
Your videos are really good and they helped so far, only with the oneToMany Mapping, I don't really believe that it has worked since so many have been having issues and the database output is not shown. If you coud fix that, then it would be perfect
Update: For anybody still struggeling look at stackoverflow.com/questions/38891442/hibernate-foreign-key-is-empty-while-using-mappedby
-> You have to set the student to the laptop and the laptop to the student. Only then it worked for me.
@@travenishere6063 This should be pinned . Than you man
Your tutorial is good but please explain in details and cover more concepts.
In ManytoOne annotations it is creating a student_rollno in laptop table but not fetching rollno it is showing null
Kunal Goswami any luck brother ?
try linking the rollno of student to laptop object [laptopobject.setStudent(student object reference)]
Hello sir, can you please make a video on how to create a hibernate project on NetBeans.
how to fetch data using criteria when the entities are mapped by onetomany or manytoone
Sir, please make a proper vedio like using interface and full pattern
Thank u very much sir
Alt+shift+R -- eclipse
select 's' then press alt+shift+r and then rename
if we need to send JSON using post call
How to structurize JSON for oneToMany and ManyToOne (For Student and Laptop Class)
Can any one help me out
Hi Navin, ctrl+2+r
Why we've use getStudent().add() here??
Then what is the work for setStudent()??
When we should use it then??
Please explain sir..
we can use the setStudent() as well .
the way would be little different.
List students = new ArrayList();
Student student = new Student();
student.addxxx();
students.add(student);
Laptop laptop = new Laptop();
laptop.setStudent(students); //not student
sorry if my answer came a lot late. just watching for first time. post to stackoverflow for quick reply .
in net-beans ctrl + r to change the variable name !
table not creating for @One-to-one mapping
Can you please provide code for each video,so that we can check easily.....Thanks
Sir how to do a bidirectional one to one mapping?
how to crate multiple records in hibernate and how to mapped
While using manytoone and onetomany... in laptop table getting foreign key value is null .. what may be the reason ?
you probably not setting the value of student into laptop object. ex : lap.setStud(sat); here lap is laptop object and sat is student object.
Any github link where we can have the above example?
To Rename all associated references right click - refactor - rename
visual studeio code supports that thing..!!!!!
Dear Navin,
I am try to persist the Customer details(Customer, Address and Country are 3 Entities are shown below),
in Country table for each persist (for the same Country) Country is inserting the again and again, please help to overcome this problem?
--------------------------------------------------------------------------------------------------------
@Entity
@Table(name = "customer")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
@Column(name = "email")
private String email;
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
private Address address;
//getters and setters
--------------------------------------------------------------------------------------------------------
@Entity
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String street;
private String city;
private String state;
private long pincode;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "address")
private Customer customer;
@ManyToOne(cascade = CascadeType.ALL, targetEntity = Country.class)
@PrimaryKeyJoinColumn
private Country country;
//getters and setters
--------------------------------------------------------------------------------------------------------
@Entity
public class Country {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String country;
@OneToMany(mappedBy = "country", cascade = CascadeType.ALL, targetEntity = Address.class)
private List address;
//getters and setters
--------------------------------------------------------------------------------------------------------
help would be appreciated!
Thank you again for everything you’ve done
Regards,
Manju