4 Replies Latest reply on Apr 3, 2006 5:49 AM by Emmanuel Bernard

    Hibernate-Validator and

    Warg Krumpf Newbie

      Hi,

      when i do

      ClassValidator cv = new ClassValidator(MyBean.class);
      cv.getInvalidValues(aReallyNewAndTransientBeanInstance);
      


      the validator will NOT complain about an invalid bean. (Altough everything works as expected when i try to persist this bean or when i check a detached bean.)

      I traced into ClassValidator to see whats happening and i found this code:

      for ( int i = 0; i < memberValidators.size() ; i++ ) {
       Member getter = memberGetters.get( i );
       if ( Hibernate.isPropertyInitialized(bean, getter.getName() ) ) {
       Object value = getMemberValue( bean, getter );
       Validator validator = memberValidators.get( i );
       if ( !validator.isValid( value ) ) {
       String propertyName = getPropertyName( getter );
       results.add( new InvalidValue( messages.get( validator ), beanClass, propertyName, value, bean ) );
       }
       }
       }


      The thing ist that
      Hibernate.isPropertyInitialized(...)
      returns false for a "new" (transient) bean, and so all my member/property constraints do NOT get checked....


      Is this a bug or is there a way to "initialize" a transient bean for use with the validatior?

      Rgds,