I was running into some classpath issues with my application which led me to look into the code of the DefaultTraversableResolver class in Hibenate Validator 4.3.2. Specifically, I was looking into the "detectJPA()" method, which doesn't seem to be able to differentiate between JPA 2 and 1 due to a missing "return" statement.
Here's the code from lines 98 to 110:
try {
Object persistence = run( NewInstance.action( persistenceClass, "persistence provider" ) );
ReflectionHelper.getValue( persistenceUtilGetter, persistence );
}
catch ( Exception e ) {
log.debugf(
"Unable to invoke %s.%s. Inconsistent JPA environment. All properties will per default be traversable.",
PERSISTENCE_CLASS_NAME,
PERSISTENCE_UTIL_METHOD
);
}
Now, shouldn't this log.debug statement be followed by a return to abort the JPA detection process while concluding that a full-featured implementation of JPA2 is not available? But this is not the case, the detection proceeds assuming a 2.0 version. Here are the directly following lines:
log.debugf(
"Found %s on classpath containing '%s'. Assuming JPA 2 environment. Trying to instantiate JPA aware TraversableResolver",
PERSISTENCE_CLASS_NAME,
PERSISTENCE_UTIL_METHOD
);
Naturally, when the conclusion is reached that JPA 2.0 is available the JPATraversableResolver is used.
|