Preconditions: Create a parent entity with OneToMany collection: @Entity @Table(name = "person") public class Person {
public Person(String name) { this.name = name; }
@Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id;
private String name;
@NotEmpty @OneToMany(mappedBy = "person", cascade = CascadeType.ALL, orphanRemoval = true) private List<Cat> cats = new ArrayList<Cat>();
public void setCats(List<Cat> cats) { this.cats.clear(); this.cats.addAll(cats); } } Reproduction steps: Create a parent entity with not empty child collection , then and save it. Then change collection to invalid state (make it empty) and try to save again . Result: Entity is successfully saved. Expected result: Constraint validation exception Additional info (SSCCE): Please find single test reproducing this bug in my github repository by link below: https://github.com/ZdesMisha/hib-bug-example |
|