Good Day all ,
I am having this problem since many days now , I was able to successfully deploy JPA2.0 appliaction on weblogic 10.3.3 , the application can run select queries using JPA. But when I try to run a create or update information on the same table I get below exception [code]
java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider
[/code]
This is very strange because in my persistence.xml I have provided hibernate as JPA provider , the persistence unit defined is like below [code]
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<!--
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
-->
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
<!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.charSet" value="UTF-8"/>
<!-- Uncomment the following two properties for JBoss only -->
<!-- property name="hibernate.validator.apply_to_ddl" value="false" /-->
<!-- property name="hibernate.validator.autoregister_listeners" value="false" /-->
</properties>
</persistence-unit>
[/code] And I have also provided the package level preferences in my weblogic.xml , below is my weblogic.xml file. As you can see I have explicitly told weblogic to prefer web app packages still it’s trying to load org.eclipse.persistence.jpa.PersistenceProvider instead of a persistenceProvider from hibernate jar.Please help me out here I am stuck at this point [code]
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd">
<wls:weblogic-version>10.3.3</wls:weblogic-version>
<wls:container-descriptor>
<wls:index-directory-enabled>false</wls:index-directory-enabled>
<!-- prefer-application-packages> <package-name>javax.persistence.spi.*</package-name>
</prefer-application-packages -->
<wls:prefer-application-packages>
<wls:package-name>antlr.*</wls:package-name>
<wls:package-name>org.apache.commons.*</wls:package-name>
<wls:package-name>org.apache.xmlbeans.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
<wls:package-name>org.hibernate.*</wls:package-name>
<wls:package-name>javax.persistence.spi.*</wls:package-name>
<wls:package-name>javax.persistence.criteria.*</wls:package-name>
<wls:package-name>javax.persistence.metamodel.*</wls:package-name>
<wls:package-name>javax.persistence.*</wls:package-name>
<wls:package-name>org.joda.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
[/code]
The whole stack trace of the above mentioned exception is [code]
java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:62)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.mycompany.peasd.dbp.entity.DrlgBestPractices.entityManager_aroundBody100(DrlgBestPractices.java:878)
at com.mycompany.peasd.dbp.entity.DrlgBestPractices.entityManager(DrlgBestPractices.java:1)
at com.mycompany.peasd.dbp.entity.DrlgBestPractices.findDrlgBestPracticesEntries_aroundBody108(DrlgBestPractices.java:904)
at com.mycompany.peasd.dbp.entity.DrlgBestPractices.findDrlgBestPracticesEntries(DrlgBestPractices.java:1)
at com.mycompany.peasd.dbp.web.DrlgBestPracticesController.list(DrlgBestPracticesController.java:669)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at com.mycompany.peasd.dbp.filters.CheckUserAuthorizationFilter.doFilter(CheckUserAuthorizationFilter.java:120)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
[/code]
I have asked the same question on below two forums in search for quick help.
https://forums.oracle.com/forums/thread.jspa?threadID=2474374&stqc=true https://www.coderanch.com/t/599976/BEA-Weblogic/Weblogic-load-PersistenceProvider-wrong-jar
You have to follow all that user1877955 said, and add this code, to avoid ClassCastException:
web.xml
<listener>
<listener-class>com.bla.Init</listener-class>
</listener>
Init.java
package com.bla;
import javax.servlet.ServletContextEvent;
public class Initjavax.servlet.ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent arg0) {
HibernatePersistenceProviderResolver.register();
}
}
HibernatePersistenceProviderResolver.java
package com.bla;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceProviderResolver;
import javax.persistence.spi.PersistenceProviderResolverHolder;
import org.hibernate.ejb.HibernatePersistence;
public class HibernatePersistenceProviderResolver implements PersistenceProviderResolver {
private static final Logger LOGGER = Logger.getLogger(HibernatePersistenceProviderResolver.class.getName());
private volatile PersistenceProvider persistenceProvider = new HibernatePersistence();
public List<PersistenceProvider> getPersistenceProviders() {
return Collections.singletonList(persistenceProvider);
}
public void clearCachedProviders() {
persistenceProvider = new HibernatePersistence();
}
public static void register() {
LOGGER.info("Registering HibernatePersistenceProviderResolver");
PersistenceProviderResolverHolder.setPersistenceProviderResolver(new HibernatePersistenceProviderResolver());
}
}
Below tip may also be helpfull for someone having the same problem
Please note that in order to run your JPA2.0 application on weblogic10.3.3 which is JPA1.0 compliant you will have to rename your persistence.xml to something like foo.xml and mentione the name of this xml file in your applicationContext.xml as (I am using Spring here )
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property value="classpath:META-INF/foo.xml" name="persistenceXmlLocation"/>
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
rename the persistenceUnit and dataSource according to the beans you have defined in your application
and you will have to define package exclusions in your weblogic.xml file as
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd"> 10.3.3
<wls:container-descriptor>
<wls:index-directory-enabled>false</wls:index-directory-enabled>
<!-- prefer-application-packages> <package-name>javax.persistence.spi.*</package-name>
</prefer-application-packages -->
<wls:prefer-application-packages>
<wls:package-name>antlr.*</wls:package-name>
<wls:package-name>org.apache.commons.*</wls:package-name>
<wls:package-name>org.apache.xmlbeans.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
<wls:package-name>org.hibernate.*</wls:package-name>
<wls:package-name>org.hibernate.validator.*</wls:package-name>
<wls:package-name>javax.persistence.*</wls:package-name>
<wls:package-name>org.joda.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
I invested few days to resolve the problem , and sharing the solution hoping it might benefit someone someday cheers.
Please find all the other details on my below blog post
http://javaiscoool.blogspot.com/2012/12/deploy-jpa20-application-on-weblogic1033.html
I finally figured a workaround for this problem , and now JPA2.0 application is running fine on Weblogic10.3.3 server.
I found out that the problem was actully relted to hibernate validator , In my JPA method code I had a "@Valid" annotation along with the object I was getting , I was trying to use hibernate validator to validate the object before persisting it , there I was getting all these exceptions. To get my application running on server I had to remove those @valid annotations from my JPA code and now everything is working fine. But now I am relying on page level validation which in my case is good enough. However the ideal solution would be to find a compatable hibernat validator jar and keep the @valid annotations in your project for the sake of better validation. For now this solution is working for me , ASA I get time I will try to find the hibernate validator jar which can work with this version on server we have and will love to have server side validation as well. I hope this workaround will save some days of someone out there :).
来源:https://stackoverflow.com/questions/13806457/weblogic-10-3-3-trying-to-load-org-eclipse-persistence-jpa-persistenceprovider-i