hardy.ferentschik wrote:
Hi,
I am tying to make sense of everything here and have a couple of questions.
What was the full stacktrace of your ClassCastException you mentioned in the beginning? Where was this happening?
When you are saying that you are using Hibernate - which dependency to you include? hibernate-entitymanager? Just depending on hibernate-core won't do you any good, unless you really don't want to use JPA. Btw, hibernate-entitymanager defines the javax.persistence.spi.PersistenceProvider service file, so provided you have this dependency in your classpath it should be found by the persistence provider resolution algorithm. This is provided Persistence.getProviders() is really calling into the classes from hibernate-jpa-2.0-api. I would not be surprised if Weblogic uses a different api version. Have you scanned all the jars in your weblogic installation (including shared/common libs)?
Sorry for all these questions, but I am trying to understand what you are trying to achieve. I also find it strange that you only get problems when adding Validator. The only point where Validator checks for JPA is in the TraversableResolver implementation. Hence, I wanted to know where exactly you get a problem. If the TraversableResolver is your problem I recommend setting a custom implementation of this interface.
--Hardy
What was the full stacktrace of your ClassCastException you mentioned in the beginning?
I only got this from logs
javax.validation.ValidationException: Call to TraversableResolver.isReachable() threw an exception
through debugging I was able to see the real cause of the problem which is
java.lang.ClassCastException: kodo.persistence.PersistenceProviderImpl cannot be cast to javax.persistence.spi.PersistenceProvider
Where was this happening?
Code:
private static PersistenceUtil util =
new PersistenceUtil() {
public boolean isLoaded(Object entity, String attributeName) {
List<PersistenceProvider> providers = Persistence.getProviders();
/* EXCEPTION HAPPENS HERE----> */ for ( PersistenceProvider provider : providers ) {
final LoadState state = provider.getProviderUtil().isLoadedWithoutReference( entity, attributeName );
if ( state == LoadState.UNKNOWN ) continue;
return state == LoadState.LOADED;
}
for ( PersistenceProvider provider : providers ) {
final LoadState state = provider.getProviderUtil().isLoadedWithReference( entity, attributeName );
if ( state == LoadState.UNKNOWN ) continue;
return state == LoadState.LOADED;
}
return true;
}
public boolean isLoaded(Object object) {
List<PersistenceProvider> providers = Persistence.getProviders();
for ( PersistenceProvider provider : providers ) {
final LoadState state = provider.getProviderUtil().isLoaded( object );
if ( state == LoadState.UNKNOWN ) continue;
return state == LoadState.LOADED;
}
return true;
}
};
}
Its happening in the line for ( PersistenceProvider provider : providers ) after List<PersistenceProvider> providers = Persistence.getProviders();
which dependency to you include ?
hibernate-core
Have you scanned all the jars in your weblogic installation (including shared/common libs)?
weblogic has kodo and openjpa jars
I don't want to use JPA , I am just depending on hibernate-core. My application does not has any JPA implementation. When deployed to weblogic which has its own JPA implemtation ( KODO and apache openjpa ) in its calss path, are getting loaded and validator assumes these are my JPA provider, so I have to tell hibernate validator not to use any PersistanceProvider found in classpath , so for me I think ideal way would be to have custom TraversableResolver , please tell me what should be the custom implementation.