Get JPA2 running on WebLogic 10.3

When you try to get JPA2 running on WebLogic 10.3 you might get this exception:

java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:632)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)

The reason is that WebLogic loads all JPA classes with the system classloader but ships JPA1. You have to force WebLogic to load the classes from within the lib folder of your web application.

Add to WEB-INF/weblogic.xml in your WAR project:

<wls:container-descriptor>
       <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
<wls:container-descriptor>

And additionally add to META-INF/weblogic-application.xml in your EAR project:

<wls:prefer-application-packages>
	<wls:package-name>javax.persistence.*</wls:package-name>
	<wls:package-name>org.hibernate.*</wls:package-name>
	<wls:package-name>org.springframework.*</wls:package-name>
</wls:prefer-application-packages>

It seems both is necessary.