简体   繁体   中英

EclipseLink Canonical Metamodel from already compiled entity classes

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM