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

is there a case in hibernate when cascading should not be used?

 
Ranch Hand
Posts: 1659
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt regarding the cascading feature of hibernate. From what I have understood, cascading is such a useful feature of hibernate where when we save in one table it also saves in the other table without us to perform the operation on the second table. When it is such a useful feature, shouldnt it be used in all the cases. We have the option to not use cascading but why would someone not use cascading. Is there a case where cascading should not be used?

thanks
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's indeed a very useful and convenient feature.

But this feature come with a price, if you do not use it wisely (when updating and/or deleting), many unnecessary cascade effects will be generated (cascade update) slowing down your performance, or deleting (cascade delete) some data you didn’t expected.
 
Monica Shiralkar
Ranch Hand
Posts: 1659
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But this feature come with a price, if you do not use it wisely (when updating and/or deleting), many unnecessary cascade effects will be generated (cascade update) slowing down your performance, or deleting (cascade delete) some data you didn’t expected.



Suppose there are tables Categories, products. If I do save operation on Categories , if cascading is not used another save operation would be required on Products which will not be automatic but will have to be specified. So what was the use of not using cascading and then specifying save operation on products too?

thanks
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:Suppose there are tables Categories, products. If I do save operation on Categories , if cascading is not used another save operation would be required on Products which will not be automatic but will have to be specified. So what was the use of not using cascading and then specifying save operation on products too?


If it makes sense to have a cascade effect when saving a Category, then just do it. It's not wrong or a bad practice! I use it myself as well, but it is always a well-informed decision (not something which is done without thought). And I always check/analyze the generated queries by the ORM tool to make sure no unneeded/unwanted/unexpected queries are generated.
 
Monica Shiralkar
Ranch Hand
Posts: 1659
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we save Category and it does not automatically save Product (cascading is not used), then we will have to do a manual save operation on Product, so why would someone not automatically save Product and do manual work.

thanks
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:If we save Category and it does not automatically save Product (cascading is not used), then we will have to do a manual save operation on Product, so why would someone not automatically save Product and do manual work.


For the exact same reasons I already explained twice in previous posts and I won't repeat them again (although third time's a charm )
 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic