Hi,
Quote:
What is the reason that annotation parameters cannot take a variable
You can do something like @Min(value = myValue) as long as myValue is a constant expression. What you can't do is referring to non-constant fields or getters that way.
One might think of a way of supporting property references, e.g. @Min(expression="${myValue}"). But one of the major design philosophies in Bean Validation is type-safety, which isn't guaranteed when using this kind of expressions. BV therefore provides the concept of class-level constraints which allows implementing logic which depends on several properties of a bean in a type-safe way.
Quote:
Would it be possible to extend Hibernate Validator with the functionality to define what object is used within the validator
We just recently discussed this sort of functionality (see https://hibernate.atlassian.net/browse/HV-514) but decided in the end against it because we couldn't find a satisfying solution for the case of Validator#validateValue(). When using this method there is no bean instance (it's used to answer "was property foo of type Bar valid if it had value baz"). This would cause issues with constraint validators relying on the object being present. The discussion on the issue provides some more background. Just use a class-level constraint if you need to access the entire bean.
Btw, @Min(value = 18, object = this) is not valid in Java, you can't refer to an object from within an annotation like this.
Best luck with your thesis and don't hesitate to come up with more questions in case you need further clarification,
--Gunnar