jmix-soft-deletion
Work with soft-deleted entities in Jmix applications. Use this skill when implementing features that need to show or hide soft-deleted records. Use this skill when bypassing soft deletion filtering to include deleted entities in queries. Use this skill when working with @DeletedDate and @DeletedBy annotations. Use this skill when implementing "show deleted" toggles in list views.
When & Why to Use This Skill
The Jmix Soft Deletion skill empowers developers to seamlessly manage logically deleted data within Jmix-based enterprise applications. It provides specialized logic for implementing 'show/hide' toggles in UI views, bypassing default deletion filters in database queries using PersistenceHints, and correctly configuring entity annotations like @DeletedDate and @DeletedBy. This skill ensures data integrity and simplifies the development of audit-friendly features and data recovery workflows.
Use Cases
- Implementing a 'Show Deleted' toggle in Jmix list views to allow administrators to view and manage archived records.
- Bypassing soft deletion filters in custom DataManager queries to include deleted entities in comprehensive reports or data exports.
- Configuring entity models with @DeletedBy and @DeletedDate annotations to automate the tracking of who deleted a record and when.
- Developing data restoration functionality by programmatically identifying and recovering soft-deleted entities.
- Optimizing UI performance by correctly handling data loader refreshes and caching when toggling the visibility of deleted records.
| name | Jmix Soft Deletion |
|---|---|
| description | Work with soft-deleted entities in Jmix applications. Use this skill when implementing features that need to show or hide soft-deleted records. Use this skill when bypassing soft deletion filtering to include deleted entities in queries. Use this skill when working with @DeletedDate and @DeletedBy annotations. Use this skill when implementing "show deleted" toggles in list views. |
Jmix Soft Deletion
When to use this skill
- When implementing a toggle to show/hide soft-deleted entities in a view
- When writing queries that need to include soft-deleted records
- When using LoadContext hints to control soft deletion filtering
- When working with entities that have @DeletedDate and @DeletedBy annotations
- When implementing restore functionality for soft-deleted entities
Instructions
Entity Setup
Entities with soft delete support have these annotations:
@DeletedBy
@Column(name = "DELETED_BY")
private String deletedBy;
@DeletedDate
@Column(name = "DELETED_DATE")
private OffsetDateTime deletedDate;
Including Soft-Deleted Entities in Queries
Use PersistenceHints.SOFT_DELETION with a LoadContext or loadDelegate:
import io.jmix.data.PersistenceHints; // IMPORTANT: NOT io.jmix.core
@Install(to = "entityDl", target = Target.DATA_LOADER)
private List<Entity> loadDelegate(LoadContext<Entity> loadContext) {
boolean showDeleted = Boolean.TRUE.equals(showDeletedCheckbox.getValue());
loadContext.setHint(PersistenceHints.SOFT_DELETION, !showDeleted);
return dataManager.loadList(loadContext);
}
SOFT_DELETION = true(default): Filters out deleted entitiesSOFT_DELETION = false: Includes deleted entities
Important Considerations
Caching: Remove
cacheable="true"from XML loaders when dynamically toggling soft deletion, as cached results may ignore hint changes.Reload on toggle: When the user toggles the show/hide deleted checkbox, call
loader.load()to refresh the data:
@Subscribe("showDeletedCheckbox")
public void onShowDeletedCheckboxChange(AbstractField.ComponentValueChangeEvent<JmixCheckbox, Boolean> event) {
entityDl.load();
}
- Visual distinction: Combine with vaadin-grid-styling skill to visually distinguish deleted entities (e.g., faded/gray appearance).