-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Doesn't validate all classes on my graph?
PostPosted: Mon Jun 25, 2007 5:34 pm 
Beginner
Beginner

Joined: Sat Jul 29, 2006 12:29 am
Posts: 27
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 Code

Code:
      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();



Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 2:27 pm 
Beginner
Beginner

Joined: Sat Jul 29, 2006 12:29 am
Posts: 27
Should it be the expected behavior? Should I open a Jira?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 3:10 pm 
Beginner
Beginner

Joined: Sat Jul 29, 2006 12:29 am
Posts: 27
Solved with ClassVaditor outside Hibernate EntityManager.

Code

Code:
   

public boolean valida(Empresa emp){
      ClassValidator<Empresa> empresaValidator = new ClassValidator<Empresa>(Empresa.class);
      InvalidValue[] invalidValues = empresaValidator.getInvalidValues(emp);
      if (invalidValues != null && invalidValues.length > 0) {
         throw new InvalidStateException(invalidValues);
      }
      else {
         return true;
      }
   }


1 - Still wondering about the Validator's behavior inside EntitYManager.

2 - It would be appropriate put this method inside my root POJO, but I've read somewhere that "It is considered a good practice to execute these lines once and cache the validator instances". So, I was thinking about put it inside my FACADE EJB. Am i correct? Is it possible using JBoss injection?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 10:24 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Are you sure the EM does not pickup @Valid invalid values.
The same code is called so it should really be the same.

If you manage to reproduce, can you post a JIRA issue and attach a simple test case, I will need to have a look.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 9:20 am 
Beginner
Beginner

Joined: Sat Jul 29, 2006 12:29 am
Posts: 27
Hi Emmanuel,

Oppened. The project is there.

http://opensource.atlassian.com/project ... owse/HV-30

Excuse me for my bad English. Would be better "Doesn't validating whole graph". :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.