OrphanRemoval on WAS 7

WAS 7

While migrating from Apache Tomcat 6 to IBM Websphere 7, in a Spring Hibernate project, you will certainly face this error:

nested exception is java.lang.NoSuchMethodError: javax/persistence/OneToMany.orphanRemoval()Z

There are many posts on the net about it. But, when dealing with IBM Websphere, it seems to be a bit different from other environments. All the issue is about persistence. All you have to do is :

1) Move your javax.persistence-2.0.0.jar to ${WAS_INSTALL_DIR}/APPSERVER/java/jre/lib/ext

2) Open configuration console and navigate to Applications->Application Types-> Websphere Entreprise Applications -> ${youApplication}

3) Click on the link “Class loading and update detection”

Webpshere 7 project details

4) In Class Loader Order, select “Classes loaded with local class loader first (parent last)”

Class loading and update detection

5) Restart WAS 7 and check if the  javax.persistence-2.0.0.jar was correctly loaded.

Websphere view - lodade classes

In the WAS 7 Redbook(WebSphere Application Server V7 Administration and Configuration Guide), they say :

The default value for class loading mode is Classes loaded with parent class
loader first. This mode causes the class loader to first delegate the loading of
classes to its parent class loader before attempting to load the class from its local
class path. This is the default policy for standard Java class loaders.
If the class loading policy is set to Classes loaded with local class loader first
(parent last), the class loader attempts to load classes from its local class path
before delegating the class loading to its parent. This policy allows an application
class loader to override and provide its own version of a class that exists in the
parent class loader.

Looks like Websphere 7, then, contains old JPA definition, without OneToMany.OrphanRemoval (which is specified in JPA 2.0).

Mykong also suggested adding hibernate-jpa-2.0-api-1.0.0.Final.jar instead of javax.persistence-2.0.0.jar

Author: Salem Ben Afia

Big Data & Java developer Search Engine Architect, Lucene Expert

2 thoughts on “OrphanRemoval on WAS 7”

Leave a reply to Salem Ben Afia Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.