diff --git a/src/main/java/com/application/munera/views/categories/CategoriesView.java b/src/main/java/com/application/munera/views/categories/CategoriesView.java index 35f7f51..94f0292 100644 --- a/src/main/java/com/application/munera/views/categories/CategoriesView.java +++ b/src/main/java/com/application/munera/views/categories/CategoriesView.java @@ -25,9 +25,8 @@ import com.vaadin.flow.router.BeforeEnterEvent; import com.vaadin.flow.router.BeforeEnterObserver; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; -import com.vaadin.flow.spring.data.VaadinSpringDataHelpers; import jakarta.annotation.security.PermitAll; -import org.springframework.data.domain.PageRequest; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.orm.ObjectOptimisticLockingFailureException; import java.util.Optional; @@ -133,6 +132,11 @@ public class CategoriesView extends Div implements BeforeEnterObserver { "Error updating the data. Somebody else has updated the record while you were making changes."); n.setPosition(Notification.Position.MIDDLE); n.addThemeVariants(NotificationVariant.LUMO_ERROR); + } catch (DataIntegrityViolationException ex) { + Notification n = Notification.show( + "Cannot delete this category as it is associated with existing expenses."); + n.setPosition(Notification.Position.MIDDLE); + n.addThemeVariants(NotificationVariant.LUMO_ERROR); } }); }