Entropy
Entropy

Reputation: 1271

Websphere and Hibernate: NoClassDefFoundError

A developer solved an issue with Hibernate 3 and WAS 7.5, wherein evidently WAS uses an old version of the hibernate jpa bridge. The developer put the jpa 2.0 jar in the ext folder to get WAS to load it in the bootstrap classloader, and so use the more recent version. This in fact works, but "feels wrong".

We recently upgraded to Hibernate 4 on some apps and did the same with 2.1. Now we are migrating to WAS 8.5.5, and it evidently needs the same treatment. It seems to have updated to use 2.0 because those apps run, but the Hibernate 4 apps need 2.1, and the ext folder trick suddenly stopped working.

So this is a perfect time to revisit this and ask, what is the "right" way to solve this problem? Or, if you don't know the "right" way, how can I do the equivalent of the ext folder trick in WAS 8.5.5?

In case you're curious, the exact error is:

java.lang.NoClassDefFoundError: javax.persistence.AttributeConverter

Upvotes: 1

Views: 950

Answers (1)

Isaac
Isaac

Reputation: 16736

(Your question mentioned WAS 7.5. There is no such version)

OK, so here it goes. If there's ever a right way to fix such issues, adding JARs into WebSphere's ext directory is certainly not it. WebSphere provides other facilities for you to add third-party libraries to the runtime; leave the ext directory alone. In fact, leave the entire WebSphere installation directory alone, if you'd like to ensure better maintainability (such as correct implementation of fixpacks, etc).

The best course of action (in my experience) would be:

  1. Bundle the JPA 2.1 JAR file, as well the Hibernate JAR file, in the EAR (place those in the EAR library; by default, that would be the /lib directory inside the EAR).
  2. Most importantly: set the EAR's classloader mode to PARENT_LAST.

Upvotes: 2

Related Questions