title: Entity enhancement on OpenJPA 2.x
body: <p>I am working on project with Spring and OpenJPA. I have a use case where I need to create entities of same data source in different projects/maven modules.</p>
  
  <p><strong>Approach 1:</strong></p>
  
  <p>I have Maven project core-entities having two modules containing set of entities with specific functionality.</p>
  
  <p>Module A - Enitity1, Enitity2, Enitity3
  Module B – Enitity4, Enitity5, Enitity6</p>
  
  <p>I have a created separate persistence units and persistence xml for each set of entities. It works fine when entities are enhanced in their respective maven modules.</p>
  
  <p><strong>Approach 2:</strong>
  In this approach I have separate modules for entities as above but the only difference is that I am using a single persistence unit for both set of entities. I have added the openjpa-maven-plugin for enhancing entities in both the modules. 
  In this case when entities are enhanced using maven plugin it gives exception saying no metadata found for entities in Module A at runtime.
  Is it because when the entities are enhanced, somehow metadata of  entities in Module A is lost at runtime.This problem does not come with entities of module B.</p>
  
  <p><strong>I have few questions around this issue:</strong></p>
  
  <p>1)Is it recommended to have multiple persistence units for same data source (as done in Approach 1)?</p>
  
  <p>2)Is there any way by which I can enhance entities in single persistence unit and different maven modules?</p>
  
  <p>3)Are the any alternate approaches of entities enhancement other than using eclipse and maven plugin? </p>
  
  <p>Below is the plugin in pom.xml of each module:</p>
  
  <pre><code>&lt;build&gt;
          &lt;plugins&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;openjpa-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;includes&gt;**/entity/**/*.class&lt;/includes&gt;
                      &lt;addDefaultConstructor&gt;true&lt;/addDefaultConstructor&gt;
                      &lt;enforcePropertyRestrictions&gt;true&lt;/enforcePropertyRestrictions&gt;
                      &lt;persistenceXmlFile&gt;${basedir}/src/main/resources/META-INF/moduleApersistence.xml&lt;/persistenceXmlFile&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;enhancer&lt;/id&gt;
                          &lt;phase&gt;process-classes&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;enhance&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
                  &lt;dependencies&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.apache.openjpa&lt;/groupId&gt;
                          &lt;artifactId&gt;openjpa&lt;/artifactId&gt;
                          &lt;version&gt;${openjpa.version}&lt;/version&gt;
                      &lt;/dependency&gt;
                  &lt;/dependencies&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
          &lt;pluginManagement&gt;
              &lt;plugins&gt;
                  &lt;!--This plugin's configuration is used to store Eclipse m2e settings 
                      only. It has no influence on the Maven build itself. --&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
                      &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
                      &lt;version&gt;1.0.0&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;lifecycleMappingMetadata&gt;
                              &lt;pluginExecutions&gt;
                                  &lt;pluginExecution&gt;
                                      &lt;pluginExecutionFilter&gt;
                                          &lt;groupId&gt;
                                              org.apache.openjpa
                                          &lt;/groupId&gt;
                                          &lt;artifactId&gt;
                                              openjpa-maven-plugin
                                          &lt;/artifactId&gt;
                                          &lt;versionRange&gt;
                                              [2.2.0,)
                                          &lt;/versionRange&gt;
                                          &lt;goals&gt;
                                              &lt;goal&gt;enhance&lt;/goal&gt;
                                          &lt;/goals&gt;
                                      &lt;/pluginExecutionFilter&gt;
                                      &lt;action&gt;
                                          &lt;ignore&gt;&lt;/ignore&gt;
                                      &lt;/action&gt;
                                  &lt;/pluginExecution&gt;
                                  &lt;pluginExecution&gt;
                                      &lt;pluginExecutionFilter&gt;
                                          &lt;groupId&gt;
                                              org.codehaus.mojo
                                          &lt;/groupId&gt;
                                          &lt;artifactId&gt;
                                              cobertura-maven-plugin
                                          &lt;/artifactId&gt;
                                          &lt;versionRange&gt;
                                              [2.5.2,)
                                          &lt;/versionRange&gt;
                                          &lt;goals&gt;
                                              &lt;goal&gt;instrument&lt;/goal&gt;
                                          &lt;/goals&gt;
                                      &lt;/pluginExecutionFilter&gt;
                                      &lt;action&gt;
                                          &lt;ignore&gt;&lt;/ignore&gt;
                                      &lt;/action&gt;
                                  &lt;/pluginExecution&gt;
                              &lt;/pluginExecutions&gt;
                          &lt;/lifecycleMappingMetadata&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
      &lt;/build&gt;
  </code></pre>