• Post Reply Bookmark Topic Watch Topic
  • New Topic

confusion regarding many to one relationship in hibernate  RSS feed

Monica Shiralkar
Ranch Hand
Posts: 921
  • 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 :


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.


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!