Question

I'd like to configure bean validation (JEE6) constraints via a properties file or database.

So for instance the Max value below would get pulled from the properties file or database. Is this possible in ?

@Max(value = 1) private int elvis;

Any suggestions on a possible approach.

Was it helpful?

Solution

It is not possible via standard Bean Validation. The default as per specification are annotations or as alternative XML.

In theory, Hibernate Validator has the (internal) concept of a MetaDataProvider and one could think of plugging in a DbMetaDataProvider. However, that would be quite some work and I am not sure that it would be worth the effort.

What is you use case anyways? Why don't you use XML?

OTHER TIPS

You can write your own constraint and validator for that. The constraint’s argument could be some identifier of the validation parameters stored in database and the validator could query database for these parameters to validate a value according to them.

Some hints:

  • See this validator for an idea how to reuse existing validators from your “über validator”.
  • See this question and this answer for a hint how to inject bean to a validator.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top