Hi,
I’m trying to validate an entity before saving, I need to check if a collection is not empty. I use @NotEmpty annotation on the field, but I still can save the object with an empty collection. However, @NotNull annotation on simple fields works perfectly. What could be the reason?
//...
public class Sale extends AbstractDocument {
@NotNull //works well
@JoinColumn(name = "COMPANY_ID")
@OneToOne(fetch = FetchType.LAZY)
private Company company;
//...
@NotEmpty // Ignored - why?
@OnDelete(DeletePolicy.CASCADE)
@Composition
@OneToMany(mappedBy = "sale")
private Set<SaleProduct> saleProducts;
//...
}
I’ve also tried to use a custom validator, as described here https://docs.jmix.io/jmix/ui/screens/validation.html
but the method isValid() of my validator is never reached, too