我想使用 Bean Validation 来注释实体中的约束,现在的问题是,实体上的关系也会得到验证吗?例如,假设我有以下实体:
@Entity
@Table(name = "css_empresa")
public class Empresa extends EntidadContactable implements Serializable,
Convert {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "EMPRESA_ID_GENERATOR", sequenceName = ConstantesSecuencias.SEQ_EMPRESA)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EMPRESA_ID_GENERATOR")
@Column(name = "cod_empresa", unique = true, nullable = false)
private Long id;
@Column(name = "num_ruc", precision = 13)
private BigDecimal numRuc;
@Column(name = "num_rup", precision = 15)
private BigDecimal numRup;
@Column(name = "txt_direccion_web", length = 255)
private String txtDireccionWeb;
@NotNull
@Column(name = "txt_nombre", nullable = false, length = 255)
private String txtNombre;
@Column(name = "txt_observaciones", length = 255)
private String txtObservaciones;
@OneToOne
@JoinColumn(name = "cod_usuario")
private Usuario administrador;
// bi-directional many-to-one association to DireccionEmpresa
@OneToMany(mappedBy = "empresa", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<DireccionEmpresa> direccionEmpresas;
--Rest of code ommited for brevity
DireccionEmpresa 实体声明如下:
@Entity
@Table(name = "css_direccion_empresa")
public class DireccionEmpresa implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "DIREMPRESA_ID_GENERATOR", sequenceName = ConstantesSecuencias.SEQ_DIREMPRESA)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "DIREMPRESA_ID_GENERATOR")
@Column(name = "cod_direccion_empresa", unique = true, nullable = false)
private Long codDireccionEmpresa;
@Column(name = "sts_predeterminado", nullable = false, length = 1)
private String stsPredeterminado;
@NotNull
@Column(name = "txt_calle_principal", nullable = false, length = 120)
private String txtCallePrincipal;
@NotNull
@Column(name = "txt_calle_secundaria", length = 120)
private String txtCalleSecundaria;
@Column(name = "txt_descripcion", length = 120)
private String txtDescripcion;
@Column(name = "txt_informacion_adicional", length = 120)
private String txtInformacionAdicional;
@NotNull
@Column(name = "txt_numero", nullable = false, length = 10)
private String txtNumero;
@NotNull
@Column(name = "txt_sector", nullable = false, length = 60)
private String txtSector;
现在的问题是,在保存 Empresa 时,Direccion Empresa 约束是否会被 BeanValidation 检查?多谢。