10 Replies Latest reply: Dec 11, 2012 10:49 AM by 440935 RSS

    Weblogic trying to load PersistenceProvider from wrong jar

    440935
      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
      java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider
      This is very strange because in my persistence.xml I have provided hibernate as JPA provider , the persistence unit defined is like below
      <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>
      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
      <?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>
      The whole stack trace of the above mentioned exception is
      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)
        • 1. Re: Weblogic trying to load PersistenceProvider from wrong jar
          Ganesh..
          Hi,
          You can get rid of this problem by adding your required jars in the classpath in setDomainEnv.sh/setDomainEnv.bat.
          e.g.

          Add the corresponding entry at the bottom of setDomainEnv.sh :

          +CLASSPATH="/oracle/<jpa-provider-specific>.jar:${CLASSPATH}"+
          +export CLASSPATH+
          • 2. Re: Weblogic trying to load PersistenceProvider from wrong jar
            Akshay Koul
            Refer:- http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic

            -Akshay
            • 3. Re: Weblogic trying to load PersistenceProvider from wrong jar
              440935
              Thakns for your reply , I don't have controll on adding any new jar files to classpath. The deployment department basically wont allow it in my company.
              That is why I am trying to find an application specific solution here.
              Pease let me know if you have any other suggesstions and tahnk you again for your reply.
              • 4. Re: Weblogic trying to load PersistenceProvider from wrong jar
                Ganesh..
                Hi,
                Weblogic server is picking up the wrong jar for you because it is able to find the class in the jar which is already loaded in memory.
                I think you cannot get away with it unless you specify the jar which should be read on priority for your application.
                • 5. Re: Weblogic trying to load PersistenceProvider from wrong jar
                  440935
                  Hello , thanks for your reply ,

                  I am trying to understand and apply what has been mentioned there for EclipseLink hoping the same steps will resolve my problem using Hibernate as persistence layer.

                  However I want to do it and export my project as WAR not EAR. Let me know if you find anyother possible solution for this problem.

                  Thanks again for your reply.
                  • 6. Re: Weblogic trying to load PersistenceProvider from wrong jar
                    440935
                    Yeah you got it buddy , now is there any way of doing it from inside the application. Please note that all the solutions to change something in server will not work in enviornment I have here. Changing something in server is almost impossible and it's not in my hand.
                    Would really appriciate if you can suggesst anyother solution for this problem.

                    Thanks and Regards
                    Sajjad Ahmed Paracha
                    • 7. Re: Weblogic trying to load PersistenceProvider from wrong jar
                      440935
                      @Ganesh

                      I have defined the package preorities already in my weblogic.xml (you can see it in my orignal post) , and this is working for all otehr cases where I am using latest jars (while weblogic has old jar files) except this case.

                      I wonder what is wrong in this specific case , I evene tried to enable "prefer web inf classes" but it then leads to alot of other exceptions.

                      Edited by: sajadparacha on Dec 11, 2012 1:23 AM
                      • 8. Re: Weblogic trying to load PersistenceProvider from wrong jar
                        Ganesh..
                        Hi,
                        If the server side is not in your control, then you are left with <prefer-web-inf-classes> element. You have to solve other problems in order to get this working :)
                        Check this link for more info:

                        http://docs.oracle.com/cd/E13222_01/wls/docs90/programming/classloading.html
                        • 9. Re: Weblogic trying to load PersistenceProvider from wrong jar
                          440935
                          :) , this is the problem my friend , I have already tried it , in fact I have tried almost everything until now. Have a look at me post on below blog

                          http://middlewaremagic.com/weblogic/?p=6725

                          Here is a copy paste from that forum

                          When I use prefer-web-inf-classes= true

                          I get below exception

                          org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘transactionManager’ defined in URL [zip:C:/Oracle/Middleware/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/DrillingBestPractices/irbqjc/war/WEB-INF/lib/_wl_cls_gen.jar!/META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean ‘entityManagerFactory’ while setting bean property ‘entityManagerFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in URL [zip:C:/Oracle/Middleware/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/DrillingBestPractices/irbqjc/war/WEB-INF/lib/_wl_cls_gen.jar!/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;

                          and when I use the package preferences like

                          antlr.*
                          org.apache.commons.*
                          org.apache.xmlbeans.*
                          org.springframework.*
                          javax.persistence.spi.*
                          org.hibernate.*
                          javax.persistence.*

                          the application is deployed , all the select queries work but when I try to run an update or create JPA operation I get below exception

                          Caused by: java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider

                          Can you please guide me why this is happening? I am a bit stuck here.
                          FYI the list of technologies I am using are

                          Spring
                          Hibernate (with JPA2)
                          Weblogic server 10.3.3


                          Let me know if you have any suggesstion after seeing this detail.
                          • 10. Re: Weblogic trying to load PersistenceProvider from wrong jar
                            440935
                            I was trying to debug my code and found while debugging that when I try to fetch list using JPA in my project I am getting it , but only when I try to save a record by clicking the save button on my page it doesn’t even go to create method defined in controller that’s very strange that probably means the URL pattern defined for this page which works fine in VM server is somehow not working in weblogic because this could be the only reason why I am not able to go at that break point I have.

                            It’s weird, also I get the Class cost exception like already mentioned
                            java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider
                            I wonder where the hell this exception is coming from ? I will dig it more and update the forum accordingly.
                            The fact that the persistence context is being loaded for all finder operations and even for deleting a record but giving above exception when trying to create or update a record is driving me crazy now :S.
                            If there was a problem loading PersitenceProvider why was it loaded when I was trying to fetch records and why it is giving ClassCastException now?