"Only the root method of an overridden method in an inheritance hierarchy may be annotated with parameter constraints" when using bean validation on a Stateless JAX-RS resource in EAP 6.x

Solution Unverified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6
  • RESTEasy
  • Bean validation
  • Stateless session bean

Issue

When using bean validation annotations on a JAX-RS resource on a class that is always an EJB, annotated with @Stateless, we have the following error. What could be wrong?

Caused by: javax.validation.ConstraintDeclarationException: Only the root method of an overridden method in an inheritance hierarchy may be annotated with parameter constraints, but there are parameter constraints defined at all of the following overridden methods: [ConstrainedMethod [location=UserResource#register(), parameterMetaData=[ParameterMetaData [location=UserResource#register(0)], name=arg0], constraints=[NotNull], isCascading=false], ParameterMetaData [location=UserResource#register(1)], name=arg1], constraints=[], isCascading=false]], hasParameterConstraints=true], ConstrainedMethod [location=UserResource$$$view9#register(), parameterMetaData=[ParameterMetaData [location=UserResource$$$view9#register(0)], name=arg0], constraints=[NotNull], isCascading=false], ParameterMetaData [location=UserResource$$$view9#register(1)], name=arg1], constraints=[], isCascading=false]], hasParameterConstraints=true]]
    at org.hibernate.validator.internal.metadata.aggregated.MethodMetaData$Builder.checkParameterConstraints(MethodMetaData.java:237) 
    at org.hibernate.validator.internal.metadata.aggregated.MethodMetaData$Builder.build(MethodMetaData.java:157) 
    at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataImpl$BuilderDelegate.build(BeanMetaDataImpl.java:586) 
    at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataImpl$BeanMetaDataBuilder.build(BeanMetaDataImpl.java:495) 
    at org.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.java:165) 
    at org.hibernate.validator.internal.metadata.BeanMetaDataManager.getBeanMetaData(BeanMetaDataManager.java:128) 
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:842) 
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateAllParameters(ValidatorImpl.java:218) 
    at org.jboss.resteasy.plugins.validation.hibernate.HibernateValidatorAdapter.applyValidation(HibernateValidatorAdapter.java:62) 
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:162) 
    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269) 
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227) 
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216) 
    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:542) 
    ... 19 more

Resolution

This is a This content is not included.known issue and will be fixed in a future EAP release. To work around the issue, try to avoid making the JAX-RS resource a stateless session bean when using bean validation.

Root Cause

An internal change in the way EJB/weld proxy objects were presented to RESTEasy affected the annotations defined on the proxy object. RESTEasy now has to account for this change in behavior. See Content from issues.jboss.org is not included.Ron Sigal's comment on the upstream Jira.

Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.