0

I cannot seem to figure out how I should get EclipseLink's CanonicalModelProcessor to generate metadata classes for entities that are mapped in an orm.xml file, and which are not source files in the current compilation unit, but instead included in the compiler's classpath.

I'm trying to do this with maven, by simply calling the compiler plugin without any further options. I could verify that the EclipseLink annotation processor executes, and finds both the persistence.xml and the orm.xml, and succeeds in processing both files. It only fails when it internally walks through the "RoundElement" classes and tries to map the against what is defined in the persistence unit. Obviously, the classes from the classpath are not in the "roundElements" list, and thus no code is generated for them, even though their metadata is present and valid in the internal PersistenceUnit object.

Does anyone have an idea how I could get this to work? Thanks!

EDIT: excerpt of pom.xml:

<dependencies>
  <dependency>  
    <groupId>com.model</groupId>
    <artifactId>app-model</artifactId>  
    <version>1.0.0</version>
  </dependency>
  <dependency>  
    <groupId>org.eclipse.persistence</groupId>  
    <artifactId>eclipselink</artifactId>  
    <version>2.5.2</version>
  </dependency>
  <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>  
    <version>2.5.2</version>
  </dependency>

  <build>
    <plugins>  
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>  
        </plugin>  
    </plugins>  
  </build>

Excerpt from orm.xml:

...
<entity class="com.model.app.AppClass">
    .... AppClass is defined in app-model artifact
</entity>
Mirko Klemm
  • 2,048
  • 1
  • 23
  • 22
  • Its not clear the structure of your persistence unit that you are attempting to run the CanonicalModelProcessor against - where are your entity class files in relation to your persistence.xml? – Chris Apr 23 '15 at 13:48
  • The entity class files are in a pre-compiled jar, which is added as a maven artifact to the maven pom of the module containing the persistence.xml and orm.xml. I'd expect the annotation processor parses the orm.xml file and then tries to resolve the classes mentioned in there, no matter whether they are found in the sources of the current module or as compiled class files in an upstream module. However, this doesn't seem to be the case. I'll try to edit my original post and add some sample code snippets to clarify... – Mirko Klemm Apr 23 '15 at 13:51

1 Answers1

0

OK - looking at the source code of the EclipseLink annotation processor, it seems that this is just "not possible". The AP walks the source elements encountered by the compiler and matches them against what has been loaded from the JPA metamodel - not the other way round. Now, I created myself a patched version of the EclipseLink annotation processor that additionally walks the entities, embeddables and mapped superclasses defined in XML and matches them against binary elements from the compile-time classpath. This way, the full metamodel can be generated.

Mirko Klemm
  • 2,048
  • 1
  • 23
  • 22