目前还不清楚我应该在类中添加@Check
(丢失类型检查!),还是在使用枚举和预定义类型映射时添加相应的检查,例如:
@Entity
public class User {
@Enumerated(EnumType.STRING)
private Status status;
@Type(type = "yes_no")
private boolean enabled = false;
}
我不喜欢手动写:
@Entity
@Check(constraints = {
"status in ('ACTIVATED', 'PENDING', 'ANONYMOUS')",
"enabled in ('Y', 'N')",
})
public class User {
有没有办法告诉Hibernate将类型约束传递给数据库约束?