0 Replies Latest reply on Jan 3, 2013 11:23 PM by Ron Sigal

    Question about validating EJBs

    Ron Sigal Master

      I have a JAX-RS resource

      @Path("/")

      @Stateless

      @SumConstraint(min=3, max=17)

      public class ErroneousResourceImpl implements ErroneousResource

      {

         ...

       

         @Inject

         @NumberOneBinding

         @Min(13)

         private int numberOne; 

          ...

       

         @Max(13)

         @Override

         public int getNumberTwo()

         {

            return numberTwo;

         }  

      }

      which implements

      @Local

      @SumConstraint(min=3, max=17)

      public interface ErroneousResource extends ResourceParent

      {

         @Max(13)

         @Override

         public abstract int getNumberTwo();

         ...

      }

      and

      public interface ResourceParent

      {

         public abstract int getNumberTwo();

      }

      where the latter interface is there so that I can apply @SumConstraint to multiple classes.

       

      The class constraint @SumConstraint and the property constraint @Max on getNumberTwo() are evaluated, but the field constraint @Min on numberOne isn't.  Drilling down, I see that the Hibernate validator is processing org.jboss.resteasy.ejb.validation.ErroneousResource$ResourceParent$1184947755$Proxy$_$$_Weld$Proxy$ and org.jboss.resteasy.ejb.validation.ErroneousResource, so the call to

      initFieldConstraints( clazz, annotationIgnores, beanMetaDataCache );

      in BeanMetaDataImpl.initClass() doesn't see field numberOne.  I realize that ErroneousResourceImpl isn't a bean type.  Still, it seems rather counterintuitive, since I don't believe that there's any relevant discussion in the Bean Validation spec.  For example, if I change ErroneousResourceImpl so that it's not an EJB but just a managed bean, then the constraint on numberOne gets processed.  Or, to put it conversely, turning a managed bean into an EJB eliminates a constraint that conforms to the Bean Validation spec.

       

      Is this behavior expected?

       

      Thanks,

      Ron