Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

confusion regarding many to one relationship in hibernate

Ranch Hand
Posts: 2513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :


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.


    Bookmark Topic Watch Topic
  • New Topic