【发布时间】:2014-01-24 22:59:34
【问题描述】:
我希望该组将一些注释合二为一,然后需要这些注释与 Hibernate-validator 和 Hibernate 的 generate-ddl 实用程序一起正常工作
我有一堆实体,其中大部分都有类似的字段。例如:
@Entity
public class Usuario implements Serializable {
@Column(name = "ID", nullable = false)
@Id
private Long id;
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "CODIGO", nullable = false)
@NotNull
private Integer code;
@Column(name = "NOMBRE", length = 75, nullable = false)
@NotNull
@Size(max = 75)
private String name;
@Column(name = "CLAVE", length = 75, nullable = false)
@NotNull
@Size(max = 75)
private String password;
@Column(name = "ES_ADMINISTRADOR")
@NotNull
@Type(type = "org.hibernate.type.NumericBooleanType")
private Boolean isAdmin;
[...]
}
我想要其他类似的东西
@Entity
public class Usuario implements Serializable {
@Column(name = "ID", nullable = false)
@Id
private Long id;
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@CodeField
private Integer code;
@Column(name = "NOMBRE")
@NameField
private String name;
@Column(name = "CLAVE", length = 75, nullable = false)
@NotNull
@Size(max = 75)
private String password;
@Column(name = "ES_ADMINISTRADOR")
@BooleanField
private Boolean isAdmin;
[...]
}
我可以这样做吗?
【问题讨论】:
-
您想将 JPA 模式标记和 JSR-303 验证组合到一个注释中...?不,没有罐头支持:(
-
@Affe 是的,我很害怕,但我希望有一些方法可以在 Hibernate 中做类似的事情。
标签: java hibernate annotations hibernate-validator