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

 

14 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
  9. Dude, you saved my day! Been battling with this for quite some time. I can't believe that I had to rename the PU xml file. Only after that, all of a sudden Weblogic was fine with it. Feels like a bug to me.

    ReplyDelete
    Replies
    1. Happy to see this blog is helping others :) , you are welcome Sebastian...

      Delete
  10. hey sajjad.. can u plz help me.. my webapp folder structure is something like

    WEB-INF
    -classes
    --xsd-source
    input.xsd
    --lib
    corebank.jar

    from corebank.jar i have one class from which i want to read the xsd file . for which i used the following code and its working in tomcat server. also its working with weblogic 10.3.3 server also while running from eclipse IDE.

    but the same thing when i am creating war file and deploy in weblogic 10.3.3 its not working however that war is working fine in tomcat.
    Please tell me the reason why this kind of issues server to server.

    ReplyDelete
    Replies
    1. URL path=Thread.currentThread().getContextClassLoader()
      .getResource("./xsd-source/input.xsd");

      SchemaFactory factory = SchemaFactory
      .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      Schema schema = factory.newSchema(url);

      Delete
    2. I am sry that time i forgot to add the code snippet so added it as a reply.. please tell me what is wrong in that.

      Delete
    3. Kumar , how are you creating your war file? I once had a problem when everything was working fine on my local server but when deployed the war file on remote it was not working. I remember when trying to create war file I was assuming every jar file I need is in my lib folder but that was not the case I was actually using an external jar file.
      The solution to that problem was always ty to export your eclipse project as war file from within eclipse as it makes sure all the dependencies internal or expternal are copied in the war file.
      Hope this will work for you if not please share the exception stacktrace here I will look into it.

      Delete