These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: deployed to weblogic and I get class cast exception
PostPosted: Thu Jul 07, 2011 8:29 am 
Newbie

Joined: Mon May 18, 2009 12:00 pm
Posts: 17
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.


Top
 Profile  
 
 Post subject: Re: deployed to weblogic and I get class cast exception
PostPosted: Thu Jul 07, 2011 2:59 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Ok, in this case the TraversableResolver is indeed your problem or in particular the DefaultTraversablerResolver which tries to determine whether you have JPA on the classpath or not. You do, but effectively you don't want to use it. Really the best would be to create a custom resolver which just returns true for both methods which you have implement. Since you also crete the Validator manually there is also no problem to just set the custom resolver during the bootstrapping. Hope this helps.

--hardy


Top
 Profile  
 
 Post subject: Re: deployed to weblogic and I get class cast exception
PostPosted: Fri Jul 20, 2012 1:03 am 
Newbie

Joined: Fri Jul 20, 2012 12:50 am
Posts: 1
Hi,

I am also getting similar exception when trying to use the Hibernate Validator.
In PersistentUtil.isLoaded():
List<PersistenceProvider> providers = Persistence.getProviders();
Persistence.getProviders() returns following entries:
[org.hibernate.ejb.HibernatePersistence@1a4e03e,
org.eclipse.persistence.jpa.PersistenceProvider@17e1fe8,
kodo.persistence.PersistenceProviderImpl@160d8e8,
org.apache.openjpa.persistence.PersistenceProviderImpl@140a17f]

The first one is from Hibernate jar and others are from org.apache.openjpa_1.0.1.0_1-1-1-SNAPSHOT.jar & com.bea.core.kodo_1.2.0.0_4-2-0.jar coming from bea weblogic lib.

Wanted to know how we can avoid loading of other Persistence providers, as it is resulting in to NEP while making call to Provider other than Hibernate.
Is there any configuration to be done by which only Hibernate Provider gets loaded in returned by
Persistence.getProviders()

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: deployed to weblogic and I get class cast exception
PostPosted: Tue Jul 02, 2013 3:55 pm 
Newbie

Joined: Tue Jul 02, 2013 3:51 pm
Posts: 1
As hardy.ferentschik is alluding to you need to provide a different TraversableResolver implementation, namely one that just returns true for both isReachable and isCascadable

Here's a simple Impl:

Code:
public class JPAIgnoreTraversableResolver implements TraversableResolver {

   @Override
   public boolean isReachable(Object traversableObject,
         Node traversableProperty, Class<?> rootBeanType,
         Path pathToTraversableObject, ElementType elementType) {
      return true;
   }

   @Override
   public boolean isCascadable(Object traversableObject,
         Node traversableProperty, Class<?> rootBeanType,
         Path pathToTraversableObject, ElementType elementType) {
      return true;
   }

}


Then to reference that Traversable Resolver when building a Validator:

Code:
ValidatorFactory factory = Validation.byDefaultProvider().configure().traversableResolver(new JPAIgnoreTraversableResolver()).buildValidatorFactory();
validator = factory.getValidator();


Hopes this helps, much better than trying to mess with dependencies and Weblogic application prefers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.