advancedSoft Deletes — @SQLDelete, @SQLRestriction/@Where
What do @SQLDelete and @SQLRestriction (or @Where) each do, and why are both needed together?
@SQLDelete replaces the actual DELETE Hibernate would generate with a custom UPDATE (e.g., setting a deleted_at timestamp), so calling remove() performs a soft delete. @SQLRestriction/@Where automatically appends a filter excluding soft-deleted rows to every query Hibernate generates for that entity. Using only @SQLDelete still requires manually filtering soft-deleted rows in every other query; using only @SQLRestriction doesn't change what remove() actually does.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response