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.