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>
After serious research i found a change here:
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:
Two ways to resolve this:
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)
(Or initialize your own Persistence Manager using JPA API)
Pass your required values in PersistentUnitInfo.
This is because once we change Websphere's classloader policy to parent last, it cannot initialize XML parsing libraries
Here is the full list:
xstream-1.2.1.jar
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)