我正在创建一个内存HSQL数据库,其中包含createin my hibernate.cfg.xml 并映射用户实体。如何在名字上设置约束以仅接受字母或性别以仅接受“M”或“F”?或者我必须在更新数据库之前验证?“
@Entity
@Table(name = "User",uniqueConstraints = {@UniqueConstraint(columnNames = "ID")})
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class User implements Serializable
{
@Id
@GeneratedValue
@Column(name = "ID",unique = true, nullable = false)
private long id;
@Column(name = "FIRST_NAME",unique = false, nullable = false, length = 100)
private String firstName;
@Column(name = "GENDER",unique = false, nullable = false)
private String gender;