I used @Check annotation at the field level, but hibernate not creates check constraints on the database. I researched that this is a bug, and @Check annotation can only be used once and at the class level. Ok, but how can I add multiple constraints at the class level? I don't want to add all conditions to the same constraint.
@Entity
public class TemplateTest{
@Id
private String id;
@Column(length = 20, nullable = false)
private String name;
@Column(precision = 5, scale = 2, nullable = false)
@Check(constraints = "AMOUNT > 0")
private BigDecimal amount;
@Column(nullable = false)
@Check(constraints = "DISPLAY_ORDER > 0")
private int displayOrder;
}
vs
@Entity
@Check(constraints = "DISPLAY_ORDER > 0 and AMOUNT > 0")
public class TemplateTest{
@Id
private String id;
@Column(length = 20, nullable = false)
private String name;
@Column(precision = 5, scale = 2, nullable = false)
private BigDecimal amount;
@Column(nullable = false)
private int displayOrder;
}