-
Type: Improvement
-
Status: Open (View Workflow)
-
Priority: Minor
-
Resolution: Unresolved
-
Affects Version/s: common 0.11
-
Fix Version/s: common 0.11
-
Labels:
Why the field-based validation is sad:
- If we place those annotations onto the fields of the class, then Hibernate Validator will access them directly via reflection. This results in the situation when the app won't work under the restrictive SecurityManager.
- If we need to use interfaces with getters, we can put annotations onto the methods in this interface.
- If we put annotations on entities managed by Hibernate, and those fields are lazy, the validation will fail since those fields are actually proxies, not our own objects. If we place the annotation upon the getter, then Hibernate will return our own object and the validation won't fail.
- Sometimes we need to add some logic to the getter which won't be triggered by HV if we use field annotations.
- Possibility to override validation in subclasses
Since it doesn't require much of efforts to move those annotations, we need to follow the most safe way: to put those annotations on the public methods. Those annotations should be placed on the getter methods.
This rule was added to the JTalks Code Conventions.
- is blocked by
-
JTALKSCOMMON-61 @UniqueField should be able to place on getter
- Open
- relates to
-
POULPE-214 BeanValidation annotations should be placed onto getters, not the fields
- Closed