Results 1 to 3 of 3

Thread: JPA2 with spring-data deployed on Websphere 7 WITHOUT Websphere JPA2 feature pack

  1. #1

    Default JPA2 with spring-data deployed on Websphere 7 WITHOUT Websphere JPA2 feature pack

    After researching for a day , finally figured out the way to run JPA 2 with Webphere 7 or below without requirement of installing Websphere JPA2 feature pack.

    Websphere 7 by default supports JPA1 but creates class loader issue when trying to run JPA2 and as always Websphere does not have any clear documentation of working around this limitation.
    Here is a very simple solution to work this around …..
    1. Persistence.xml file FIX

    Two ways to resolve this –

    a. Get rid of persistence.xml file. or
    b. Rename persistence.xml to persistence_WAS.xml

    Sample code
    Code:
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    	<property name="persistenceXmlLocation" value="classpath:META-INF/persistence_WAS.xml"/>
    </bean>
    This is because J2EE container by default looks for persistence.xml under META-INF/ of web application and keeping this will cause websphere7 to initialize JPA1 ignoring request of using JPA2.
    Getting rid of persistence.xml was a choice for me by using Spring Data config.
    (Throwing Validation exception of XML version attribute is invalid)

    2. Manual Initialize your persistence Manager ( remove dependency on Websphere )
    LocalContainerEntityManagerFactoryBean is provided by Spring to create persistence Manager.

    (Or initialize your own Persistence Manager using JPA API)

    Pass your required values in PersistentUnitInfo.

    3. Add XML Parsing Jars to you application lib

    This is because once we change Websphere's classloader policy to parent last, it cannot initialize XML parsing libraries

    Here is the full list -

    1. xalan-2.7.jar
    2. xbean-2.2.0.jar
    3. xbean_xpath-2.2.0.jar
    4. xercesImpl-2.6.2.jar
    5. xml-apis-2.8.jar
    6. xmlpublic-2.2.0.jar
    7. XmlSchema-1.4.7.jar
    8. xpp3-1.1.3.4.O.jar
    9. xstream-1.2.1.jar


    4. Change class loader policy on Websphere application server

    Make Websphere to load its internal and extension JARs at last after loading all JARs from your WAR or EAR file - PARENT_LAST does the trick here.

    Here is path to update – Steps

    Under Applications > Application Types > WebSphere enterprise applications

    Select the deployed application -

    Enterprise Applications > JPA2-Application > Manage Modules

    Choose the WAR file eg. JPA2-Application.war

    Change the Class loader order setting to Classes loaded with local class loader first(parent last)
    Under Class loader viewer you can see your ClassLoader - Search Order - You can see Jars and classes from your EAR are loaded first.

    Here is the screen shot.

    server-setting.jpgserver-setting.jpg

    That’s it – Restart your server and your JPA 2 Application will start working in Websphere 7
    and NO NEED of installing Websphere JPA2 feature pack.

  2. #2

    Default

    JPA 2 on Websphere 7 with spring

  3. #3
    Join Date
    Jan 2013
    Posts
    1

    Default WAS 7 | Two step solution

    WAS 7
    1. Environment -> Shared Library -> Create a new SharedLibrary -> Give the classpath as your JPA2WebApplication/Web-Inf/lib
    2. WebApplication Server -> Your Server -> Java and Process Management -> Class Loader -> New - Classes loaded with application class loader first -> Add the shared library created in the previous step.

    Make sure under Server -> Class Loader is Single and Parent at last is selected.

    Restart the server.


















    Quote Originally Posted by shanti.b.sharma.g1 View Post
    After researching for a day , finally figured out the way to run JPA 2 with Webphere 7 or below without requirement of installing Websphere JPA2 feature pack.

    Websphere 7 by default supports JPA1 but creates class loader issue when trying to run JPA2 and as always Websphere does not have any clear documentation of working around this limitation.
    Here is a very simple solution to work this around �..
    1. Persistence.xml file FIX

    Two ways to resolve this �

    a. Get rid of persistence.xml file. or
    b. Rename persistence.xml to persistence_WAS.xml

    Sample code
    Code:
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    	<property name="persistenceXmlLocation" value="classpath:META-INF/persistence_WAS.xml"/>
    </bean>
    This is because J2EE container by default looks for persistence.xml under META-INF/ of web application and keeping this will cause websphere7 to initialize JPA1 ignoring request of using JPA2.
    Getting rid of persistence.xml was a choice for me by using Spring Data config.
    (Throwing Validation exception of XML version attribute is invalid)

    2. Manual Initialize your persistence Manager ( remove dependency on Websphere )
    LocalContainerEntityManagerFactoryBean is provided by Spring to create persistence Manager.

    (Or initialize your own Persistence Manager using JPA API)

    Pass your required values in PersistentUnitInfo.

    3. Add XML Parsing Jars to you application lib

    This is because once we change Websphere's classloader policy to parent last, it cannot initialize XML parsing libraries

    Here is the full list -

    1. xalan-2.7.jar
    2. xbean-2.2.0.jar
    3. xbean_xpath-2.2.0.jar
    4. xercesImpl-2.6.2.jar
    5. xml-apis-2.8.jar
    6. xmlpublic-2.2.0.jar
    7. XmlSchema-1.4.7.jar
    8. xpp3-1.1.3.4.O.jar
    9. xstream-1.2.1.jar


    4. Change class loader policy on Websphere application server

    Make Websphere to load its internal and extension JARs at last after loading all JARs from your WAR or EAR file - PARENT_LAST does the trick here.

    Here is path to update � Steps

    Under Applications > Application Types > WebSphere enterprise applications

    Select the deployed application -

    Enterprise Applications > JPA2-Application > Manage Modules

    Choose the WAR file eg. JPA2-Application.war

    Change the Class loader order setting to Classes loaded with local class loader first(parent last)
    Under Class loader viewer you can see your ClassLoader - Search Order - You can see Jars and classes from your EAR are loaded first.

    Here is the screen shot.

    server-setting.jpgserver-setting.jpg

    That�s it � Restart your server and your JPA 2 Application will start working in Websphere 7
    and NO NEED of installing Websphere JPA2 feature pack.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •