java.lang.NoClassDefFoundError: org/apache/openjpa/enhance/PersistenceCapable

My current project is using JPA, heavily. JPA is a spec/standard/interface and I’m using the Hibernate implementation for it, but I import the entities from a different maven module. The entities module has a dependency on JPA, but not on Hibernate. So when I run my unit tests, I suddenly get a:
java.lang.NoClassDefFoundError: org/apache/openjpa/enhance/PersistenceCapable
Openjpa? Where does that come from?
The colleague who is developing the entities module uses openjpa for testing, so it’s declared with a test scope. The source code does not reference PersitenceCapable anywhere, so we were quite baffled as to where that reference lies.
It turns out that openjpa preferably instruments entity classes at compile time, so my colleague did that in the maven pom with a plugin:
<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>openjpa-maven-plugin</artifactId>
                <version>1.2</version>
... 
</plugin>
That plugin outputs entity class files which do have a dependency on openjpa.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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