[
http://opensource.atlassian.com/projects/hibernate/browse/HV-492?page=com...
]
Hardy Ferentschik commented on HV-492:
--------------------------------------
Here is the thing. The Bean Validation specification actually dictates how to access the
values for validation:
{quote}
Constraint declarations can be applied on both fields and properties for the same object
type. The same constraint
should however not be duplicated between a field and its associated property (the
constraint validation would be
applied twice). It is recommended for objects holding constraint declarations to adhere to
a single state access
strategy (either annotated fields or properties).
When a field is annotated with a constraint declaration, field access strategy is used to
access the state validated by
such constraint.
When a property is annotated with a constraint declaration, property access strategy is
used to access the state validated
by such constraint.
{quote}
Validation of CGLIB enhanced Objects always return null
-------------------------------------------------------
Key: HV-492
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HV-492
Project: Hibernate Validator
Issue Type: Bug
Affects Versions: 4.1.0.Final, 4.2.0.Beta2
Environment: Hibernate Validator 4.1.0-final and 4.2.0-BETA2, cglib 2.2
Reporter: Christian Fehmer
A validation of a cglib enhanced object will always validate "null".
The validator (i tested it with an custom validator) always gets "null" as the
value in the isValid method. The cglib enhanced object has a field "selection"
and a getter/setter pair for this field. The hibernate validator uses the
org.hibernate.validator.util.ReflectionHelper to access the field selection directly. That
fails on a cglib enhanced object.
My workaround for now: I replaced the
org.hibernate.validator.util.ReflectionHelper.getValue method. When object is a cglib
enhanced object i invoke the getter method instead of accessing the field directly.
replaced method:
{code}
public static Object getValue(Member member, Object object) {
Object value = null;
if (member instanceof Method) {
...
} else if (member instanceof Field) {
// FIX: use getter method on cglib fields
if (object.getClass().getName().contains("$$")) {
String methodName = member.getName();
methodName = "get"+ String.valueOf(methodName.charAt(0)).toUpperCase()+
methodName.substring(1);
try {
Method method = member.getDeclaringClass().getMethod(
methodName);
method.setAccessible(true);
value = method.invoke(object);
} catch (Exception e) {
throw new ValidationException("Unable to access "
+ methodName, e);
}
} else {
...
}
}
return value;
}
{code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira