Follow by Email

Saturday, December 15, 2012

Deploy JPA2.0 application on weblogic10.3.3



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
 
 
 
<?xml version="1.0" encoding="UTF-8"?>
    <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>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>
</wls:weblogic-web-app>
 

I invested few days to resolve the problem , and sharing the solution hoping it might benefit someone someday.

Below are some related threads I created for this problem , there you will find the details of problems you can face and the recomended solutions , but the solution provided above is working for me now and is gurenteed :).

https://www.coderanch.com/t/598227/Spring/Create-update-operations-ROO-causing

http://www.coderanch.com/t/599976/BEA-Weblogic/Weblogic-load-PersistenceProvider-wrong-jar

http://stackoverflow.com/questions/13806457/weblogic-10-3-3-trying-to-load-org-eclipse-persistence-jpa-persistenceprovider-i/13898999#13898999

https://forums.oracle.com/forums/thread.jspa?threadID=2474374&stqc=true

If you want to understand why we have package exclusions in our weblogic.xml file then below blog will help you alot understanding class loading in weblogic and why we need the package exclusions , I don't want to repeat the same story here , and this guy has written a great blog on it already
http://middlewaremagic.com/weblogic/?p=6725

 

8 comments:

  1. This is great Sajjad. May I know how you are handling creating the oracle database connections?

    ReplyDelete
  2. Yes Asem , I am creating connection per user.We can't use connection pool in this case. I used spring's class called UserCredentialDatasourceAdapter to which the datasource is passed and we make the datasource just after getting user credentials from login page. I used Spring Security which saves the user credential in SpringSecurityCotext object so that you can get it anytime anywhere in the application if needed.We create a connection only when it is needed and close it ASA database operations are done.

    ReplyDelete
  3. I can see some good trefic coming on this blog post :) , I would be happy to help anyone out there trying to implement the solution I proposed here and facing any problem.
    Guys it will be free of cost :) you can approch me any time.

    Let me know if you need any sort of help regarding this issue.

    Thanks for visiting my blog.

    ReplyDelete
  4. Thanks man, you saved me the few days.

    Cheers,
    Adrian

    ReplyDelete
  5. You are welcome anytime Adrian , can you please share what problem you were facing and how this blog post helped you?

    ReplyDelete
  6. Hi Sajjad, i have the same problem but i can't fix it.
    I try to install an application over Weblogic 10.3.4.0 but without success.
    I have the follow packages from my web app.
    WEB-INF
    lib
    all libs here
    fonts
    ..
    classes
    META-INF
    persistence.xml
    applicationContext.xml
    weblogic.xml
    web.xml
    dwr.xml
    META-INF

    My persistence.xml looks like:




    org.hibernate.ejb.HibernatePersistence
    jdbc/MySQLDBDS







    My weblogic.xml


    antlr.*
    org.apache.commons.*
    org.apache.xmlbeans.*
    org.springframework.*
    org.hibernate.*
    org.hibernate.validator.*
    *.PersistenceProvider
    javax.persistence.*
    org.joda.*


    Could you tell me what it's wrong


    redgars

    ReplyDelete
  7. the code it´s here

    persistence.xml
    http://hostcode.sourceforge.net/view/760
    weblogic.xml:
    http://hostcode.sourceforge.net/view/761
    applicationContext.xml:
    http://hostcode.sourceforge.net/view/762


    ReplyDelete
  8. Hello Joge I just saw your message I am in office rite now and can't open the links you provided , Will try to access it at home and see if I can help you.

    ReplyDelete