我是新來的hibernate &春天,我想知道如何使用hibernate驗證器映射實體類,例如:如果我有以下實體類它們之間有一對一的關係。我怎樣才能驗證這兩個實體使用類似@NotNull的hibernate驗證器的字段:「personName,personPhone,personEmail,addressLine1,addressLine2,city,state,& zipCode」。如何在映射實體上使用hibernate驗證器
@Entity
@Table (name = "person")
public class FacilityModel {
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Column (name = "pers_id")
private int persId;
@Column (name = "pers_name")
private String personName;
@OneToOne (cascade = CascadeType.ALL)
@JoinColumn (name = "pers_Addr_Id")
private AddressModel address;
@Column (name = "pers_phone_no")
private String personPhone;
@Column (name = "pers_email")
private String personEmail;
而且
@Entity
@Table (name = "address")
public class AddressModel {
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Column (name = "addr_id")
private int addrId;
@Column (name = "addr_address_line1")
private String addrLine1;
@Column (name = "addr_address_line2")
private String addrLine2;
@Column (name = "addr_city")
private String city;
@Column (name = "addr_state")
private String state;
@Column (name = "addr_country")
private String country;
@Column (name = "addr_zip_code")
private String zipCode;
而且,做我需要在比處理方法@Valid註釋和BindingResult其他控制器的任何額外的代碼。
請任何人幫我這個。
如果有人知道請幫幫我。 – karthi