Skip to content

Commit b9245ae

Browse files
committed
add @softdelete to Guide
1 parent 6159713 commit b9245ae

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

documentation/src/main/asciidoc/introduction/Advanced.adoc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,29 @@ List documents =
181181
For much more information, see {envers-doc}[the User Guide].
182182
****
183183

184-
Another closely-related problem is multi-tenancy.
184+
Historically, filters where often used to implement soft-delete.
185+
But, since 6.4, Hibernate now comes with soft-delete built in.
186+
187+
[[soft-delete]]
188+
=== Soft-delete
189+
190+
Even when we don't need complete historical versioning, we often prefer to "delete" a row by marking it as obsolete using a SQL `update`, rather than by executing an actual SQL `delete` and removing the row from the database completely.
191+
192+
The link:{doc-javadoc-url}org/hibernate/annotations/SoftDelete.html[`@SoftDelete`] annotation controls how this works:
193+
[source,java]
194+
----
195+
@Entity
196+
@SoftDelete(columnName = "deleted",
197+
converter = TrueFalseConverter.class)
198+
class Draft {
199+
200+
...
201+
}
202+
----
203+
The `columnName` specifies a column holding the deletion status, and the `converter` is responsible for converting a Java `Boolean` to the type of that column.
204+
In this example, `TrueFalseConverter` sets the column to the character `'F'` initially, and to `'T'` when the row is deleted.
205+
206+
Another feature that you _could_ use filters for, but now don't need to, is multi-tenancy.
185207

186208
[[multitenancy]]
187209
=== Multi-tenancy

0 commit comments

Comments
 (0)