I've added hibernate validator to my project, and annotated my class with the relevant constraints. This is my pom.xml:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
and this is the annotated class:
public class EmployeeProject extends PanacheEntity {
@NotNull
@ManyToOne
private Employee employee;
@NotNull
@ManyToOne
private Project project;
@Column
@Min(value = 1)
private int quantity;
}
When I try to persist a not valid bean - null employee/project and/or non-positive quantity - through Java code, a validation exception is raised, as expected.
However, when I try to persist a not valid tuple directly into the database, surprisingly no exceptions or DB errors are raised. Indeed the reason is that the employee_project
auto-generated by Hibernate have no validation constraints - just the two foreign keys constraints. I know there is no simple way to translate @Min
in SQL, but boy I was at least expecting a NOT NULL on employee_id
and project_id
!
Is this the regular behavior, or am I missing something?