Hi,
I would like to validate my whole graph (even Empresa - root bean), but seems that Validator is stopping at the first invalid entity(EnderecoOficial), cause I only get EnderecoOficial's errors. I have also tried with @Valid on my root entity(Empresa), but without success. Is there any way to accomplish this?
Thanks.
Hibernate version:
16:41:55,765 INFO Version:15 - Hibernate EntityManager 3.2.1.GA
16:41:55,796 INFO Version:15 - Hibernate Annotations 3.2.1.GA
16:41:55,812 INFO Environment:509 - Hibernate 3.2.3
16:41:55,812 INFO Environment:542 - hibernate.properties not found
16:41:55,812 INFO Environment:676 - Bytecode provider name : cglib
16:41:55,828 INFO Environment:593 - using JDK 1.4 java.sql.Timestamp handling
Mapping documents:
Code:
@Entity
@Table(name = "EMPRESA")
public class Empresa implements Serializable {
@Id @GeneratedValue
private Long id;
@Version
private int version = 0;
//@Valid
@Length(min=1, max=3)
private String nome;
//@Valid
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="idEnderecoOficial")
private EnderecoOficial enderecoOficial;
//@Valid
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="idEnderecoFinanceiro")
private EnderecoFinanceiro enderecoFinanceiro;
....................
Code:
@Entity
@Table(name = "ENDERECO_OFICIAL")
public class EnderecoOficial extends Endereco {
public EnderecoOficial() {
}
public EnderecoOficial(String pais, String unidadeFederativa, String cidade, String bairro, String rua, String numero, String complemento, String cep, HorarioAtendimento horarioAtendimento) {
super(pais, unidadeFederativa, cidade, bairro, rua, numero, complemento, cep, horarioAtendimento);
}
}
Code:
@MappedSuperclass
public abstract class Endereco implements Serializable {
@Id @GeneratedValue
private Long id;
private String logradouro;
private String numero;
private String complemento;
@Length(min=5, max=5)
private String cep;
@Length(min=1, max=3)
private String pais;
Test CodeCode:
tx.begin();
try {
emp1 = empresaFACADE.persiste(emp1);
}
catch (InvalidStateException e) {
InvalidValue[] iv = e.getInvalidValues();
System.out.println("Bean->" + iv[0].getBean());
System.out.println("Message->" + iv[0].getMessage());
System.out.println("Property->" + iv[0].getPropertyName());
System.out.println("Bean->" + iv[1].getBean());
System.out.println("Message->" + iv[1].getMessage());
System.out.println("Property->" + iv[1].getPropertyName());
System.out.println("Bean->" + iv[2].getBean());
System.out.println("Message->" + iv[2].getMessage());
System.out.println("Property->" + iv[2].getPropertyName());
}
tx.commit();