Hi,
I am 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'm looking into the "detectJPA()" method, which doesn't seem to be able to differentiate between JPA 2 and 1. It seems to me that a "return" statement is missing that is causing this issue.
Here's the code from lines 98 to 110:
Code:
// try to invoke the method to make sure that we are dealing with a complete JPA2 implementation
// unfortunately there are several incomplete implementations out there (see HV-374)
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:
Code:
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 while it's not, the JPATraversableResolver is used, which blows up when it calls:
Code:
return Persistence.getPersistenceUtil().isLoaded( traversableObject, traversableProperty.getName() );
Am I right about this or is there something that I missed? Is this a well-known issue? Is there a way to work around this and force Validator not to use the JPATraversableResolver?