4

We are trying to use Hibernate as JPA Provider on WebSphere Application Server 7.0. But We are getting following exception.

javax.ejb.EJBException: Injection failure; nested exception is:

java.lang.IllegalStateException: EntityManagerFactory has not been created for PU : PuId=data_commonweb#data_ejb_common.jar#data_common

Caused by: java.lang.IllegalStateException: EntityManagerFactory has not been created for PU : PuId=data_commonweb#data_ejb_common.jar#data_common

Persistense.xml is as below:

    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/db_ds</jta-data-source>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialet"/>
        <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" />
        <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
        <property name="openjpa.TransactionMode" value="managed"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
    </properties>
</persistence-unit>

Ferrmolina
  • 2,737
  • 2
  • 30
  • 46
Seshagiri
  • 728
  • 5
  • 10
  • That looks like an internal error. Were there other errors in SystemOut.log before that error that could have been the cause? – Brett Kail Jun 08 '12 at 17:21

2 Answers2

1

After serious research i found a change here:

http://forum.spring.io/forum/spring-projects/data/115284-jpa2-with-spring-data-deployed-on-websphere-7-without-websphere-jpa2-feature-pack

JPA2 with spring-data deployed on Websphere 7 WITHOUT Websphere JPA2 feature pack Mar 22nd, 2012, 08:52 PM 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:

  • Get rid of persistence.xml file. or
  • 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)

  1. 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.

  1. 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:

  • xalan-2.7.jar
  • xbean-2.2.0.jar
  • xbean_xpath-2.2.0.jar
  • xercesImpl-2.6.2.jar
  • xml-apis-2.8.jar
  • xmlpublic-2.2.0.jar
  • XmlSchema-1.4.7.jar
  • xpp3-1.1.3.4.O.jar
  • xstream-1.2.1.jar

    1. 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.

in my case don't need the extra libs(step 3)

Sergey Bespalov
  • 1,746
  • 1
  • 12
  • 29
nekperu15739
  • 3,311
  • 2
  • 26
  • 25
-2

We were getting this error for all JPA related issues. We solved configuring Hibernate as JPA by following https://www.ibm.com/developerworks/mydeveloperworks/wikis/form/anonymous/api/library/53181ccd-bcd4-431f-b968-0b5f6d46d652/document/192a432b-28bb-4080-b037-345e5d83da76/attachment/61e74f67-1d60-4120-ba25-ad7264c9f4f6/media/AlternateJPAProviders_TestReport.pdf.

Sumurai8
  • 20,333
  • 11
  • 66
  • 100
Seshagiri
  • 728
  • 5
  • 10
  • 1
    Also see the IBM JPA forum https://www.ibm.com/developerworks/community/forums/html/forum?id=11111111-0000-0000-0000-000000001843 and IBM Developerworks Wiki. https://www.ibm.com/developerworks/community/wikis/home?lang=en – David Victor Aug 28 '13 at 07:21
  • 1
    Please do not only post link-only answers. If the link contains the answer, put the relevant part of the answer in your answer on StackOverflow. If the content behind the link changes, or the content is removed, your answer does not answer this question anymore. – Sumurai8 Aug 28 '13 at 07:26
  • 1
    @DavidVictor Thanks for your edit btw; I have no clue why people refused your edit, but I now did it on personal title. – Sumurai8 Aug 29 '13 at 06:12