Hey,
What you want to achieve is not possible due to limitations of the Java annotation system. In particular one can't have an annotation member which takes
any enumeration value (Enum<?>), one can only define annotation members which accept
one specific enumeration type.
As the programmatic API is resembling the possiblities of annotation-based constraint declaration, the same limitation applies there. So you'd have to define a custom constraint annotation type for this. The reference guide disscusses in [1] in detail this particular case of creating a constraint based on an enumeration.
You could then declare constraints of that type via the API (see [2] for more details):
Code:
constraintMapping
.type(Product.class)
.property("status", ElementType.FIELD)
.constraint( new GenericConstraintDef<>( ProductStatusOf.class )
.param( "value", ProductStatus.ACTIVE )
);
Hth,
--Gunnar
[1] http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-customconstraints-simple
[2] http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-programmatic-api