title: How can I perform build time enhancement of JPA entities while running an Arquillian test?
body: <p>Technology stack: Arquillian embedded-tomee, HSQLDB, openJpa, jdk 1.8.</p>
  
  <p>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.</p>
  
  <pre><code>&lt;openjpa-2.4.0-r422266:1674604 fatal general error&gt;
  org.apache.openjpa.persistence.PersistenceException: null
  </code></pre>
  
  <p>I have all my entities added to the <code>test-persistence.xml</code> and is correctly placed under <code>src/test/resources</code>.</p>
  
  <p><strong>The Initial Problem</strong>
  I tried setting <code>Runtime Unenhanced Classes</code> to <code>supported</code> and hoped that the enhancement would occur at runtime inside the <code>Arquillian-Embedded-Tomee</code> 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.
  <strong>NOTE</strong>: The runtime enhancement works perfectly fine inside the <strong>actual</strong> deployed tomee container. Just doesn't work inside Arquillian.</p>
  
  <p><strong>First Approach to solve the above problem:</strong>
  I didn't want to expose my entities as public. So switched to <code>build-time-enhancement</code> using the <code>openjpa maven plugin</code> as described <a href="http://people.apache.org/~dwoods/openjpa/site/enhancement-with-maven.html" rel="nofollow noreferrer">here</a>.
  Had some success with this approach. Could actually see and verify that while running <code>mvn clean install</code> the enities were being enhanced.</p>
  
  <p><strong>build output:</strong></p>
  
  <pre><code> --- 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".
  </code></pre>
  
  <p>and so on...</p>
  
  <p>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.</p>
  
  <pre><code>&lt;property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/&gt;
  </code></pre>
  
  <p>because of which I concluded that the <code>openjpa-maven-plugin</code> was working as expected.</p>
  
  <p>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 <code>javaagent</code> behind the scenes?</p>
  
  <p><strong>Not knowing what to do, I switched to a different(???) approach:</strong>
  Tried running enhancement using <code>javaagent</code> as described to a similar question <a href="https://stackoverflow.com/questions/18651500/arquillian-integration-tests-and-openjpa-enhancement">posted here</a>. Had no success with this.
  Ended up with the below error:</p>
  
  <pre><code>&lt;&lt;&lt; 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
  </code></pre>
  
  <p>Question 3: <strong>So how can I set up build time enhancement, and also make sure that the enhancements work for every unit test that I run?</strong></p>
  
  <p>Question 4: <strong>Even better how can I(If popssible) set up build time enhancement to occur only for tests running inside of Arquillian.</strong></p>
  
  <p>Or am I approaching this all wrong to begin with?</p>