I would like the group some annotation in one and then need that the annotations work fine with Hibernate-validator and the generate-ddl utily of Hibernate
I have a bunch of entities and most of then had similar fields. For example:
@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;
[...]
}
And I want have something like this other
@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;
[...]
}
Can I do that?
No, that's not possible. The composition feature of Bean Validation only allows to aggregate several constraint annotations into a new higher-level constraint, but this does not take any JPA annotations into account.