Technology stack: Arquillian embedded-tomee, HSQLDB, openJpa, jdk 1.8.
I have spent several days trying to figure out how I can get this all to work together and have come very close IMO. And now I am stuck with this one very generic error.
<openjpa-2.4.0-r422266:1674604 fatal general error>
org.apache.openjpa.persistence.PersistenceException: null
I have all my entities added to the test-persistence.xml
and is correctly placed under src/test/resources
.
The Initial Problem
I tried setting Runtime Unenhanced Classes
to supported
and hoped that the enhancement would occur at runtime inside the Arquillian-Embedded-Tomee
container. Had no luck there. Kept getting the error that some of my entities didn't have a public/protected no-args constructor which is required for runtime enhancement.
NOTE: The runtime enhancement works perfectly fine inside the actual deployed tomee container. Just doesn't work inside Arquillian.
First Approach to solve the above problem:
I didn't want to expose my entities as public. So switched to build-time-enhancement
using the openjpa maven plugin
as described here.
Had some success with this approach. Could actually see and verify that while running mvn clean install
the enities were being enhanced.
build output:
--- openjpa-maven-plugin:1.2:enhance---
some-persistent-unit INFO [main] openjpa.Tool - Enhancer running on
type "class someClass".
some-persistent-unit INFO [main] openjpa.Tool - Enhancer running on
type "class someotherclass".
and so on...
But the problem here is: The tests pass only during maven build. If I try to run the individual tests in a test class or all of the tests in that test class, they fail. And also in this approach I disabled the runtime support for unenhanced classes in my persistence-context.
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
because of which I concluded that the openjpa-maven-plugin
was working as expected.
Question 1: Is this the expected behavior? Do the tests not work outside of a maven build?
Question 2: Is the openjpa plugin providing a javaagent
behind the scenes?
Not knowing what to do, I switched to a different(???) approach:
Tried running enhancement using javaagent
as described to a similar question posted here. Had no success with this.
Ended up with the below error:
<<< ERROR! org.apache.openjpa.persistence.ArgumentException: This
configuration disallows runtime optimization, but the following listed types
were not enhanced at build time or at class load time with a javaagent: "
List of entities described in test-persistence.xml
Question 3: So how can I set up build time enhancement, and also make sure that the enhancements work for every unit test that I run?
Question 4: Even better how can I(If popssible) set up build time enhancement to occur only for tests running inside of Arquillian.
Or am I approaching this all wrong to begin with?
Q1: if your IDE doesnt run openjpa plugin but only do a compilation then you'll miss the enhancement yes
Q2: no, both the plugin and javaagent uses the same enhancement implementation but you can see them as different hooks (build vs runtime)
Q3: depends your IDE, with eclipse you need the lifecycle plugin to configure openjpa and with Intellij you need to add openjpa:enhance after Make phase in the run configuration
Q4: with tomee remote it is done automatically
I think using the javaagent is still the best way to solve the enhancement, you really just need to ensure maven and/or your test configuration have -javaagent:/path/to/openejb-javaagent.jar