Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

confusion regarding many to one relationship in hibernate

 
Ranch Hand
Posts: 1659
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning hibernate and I have a confusion regarding hibernate many to one relationship.


Suppose we have tables VENDOR and CUSTOMER such that multiple customers can have one vendor.



many CUSTOMERS - one vendor

relationship in this case is MANY TO ONE CASE.

What we have achieved: if we save(customer1), save(customer2), the vendor data will also be saved in vendor table. (Provided we have done CASCADE ALL)



many CUSTOMERS can have one VENDOR means that :

one VENDOR- many CUSTOMERS

relationship: ONE TO MANY CASE

What we have achieved using this: if We do operation save(vendor), customer details (customer 1,customer2) will be saved in customer tables also. (Provided we have done CASCADE ALL)

Suppose we do the other way round. What if we save customer details : save(customer1), save(customer2). Will the vendor details be also saved automatically in the Vendor table.


If the answer is yes then this is same as what we have achieved in Many to one case discussed above in the Many to One case. Then Many to one case is not required at all. Instead of Many to one case of Many Customers one Vendor and save operation on CUSTOMERS we will do the one to many and do save operation on VENDOR which will also do a save in CUSTOMER table.

thanks






 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic