Nurmuhammad
Nurmuhammad

Reputation: 136

How can I ignore cascade when calling persist/merge

How can I ignore cascade saving/updating when calling persist(..)/ merge(..) without removing cascade annotation?

Upvotes: 1

Views: 1781

Answers (2)

Stevi Deter
Stevi Deter

Reputation: 1683

If you find you have two different use cases, one that makes using the save/update annotation useful, and one that makes it not useful, I'd create a second class, either using inheritance or simply a different class, depending on the complexity of your model. One mapping will omit the cascade annotation, to be used in those cases you don't want it to happen.

Upvotes: 1

Bozho
Bozho

Reputation: 597274

You can't. Two workarounds come to my mind:

  • empty the collections before persisting
  • use HQL to insert/update

Neither is a good option though.

Upvotes: 1

Related Questions