SKILL.md
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 entities
SOFT_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).