2014-10-27 180 views
3

我正在尝试使用hibernate-jpamodelgen与maven-processor-plugin一起使用配置from this answer生成我的JPA元模型作为我的Maven版本的一部分。如何将JPAMetaModelEntityProcessor配置为不会出现“重复类”错误?

然而,当我做的构建,我得到以下错误,当我尝试做一个mvn clean install

[ERROR] C:\Users\ArtB\Documents\code\xxx\target\classes\me\Page_.java:[11,16] error: duplicate class: me.Page_ 

从一些调查它看起来像问题是,产生的元模型似乎发生两次或者其他的东西。

如果我运行clear; mvn clean generate-sources; ls -l target\generated-sources\apt\me我只是文件_Page.java,没有其他文件。

compile阶段target\classes\文件夹只包含\me\_Page.java ...因为我想.class文件应该出现在“\目标\类”文件夹中,这似乎很奇怪。

我运行构建与调试(即-X),并没有看到任何可疑的。


我怀疑它的问题,但这里是我的模型。

package me; 

@Entity 
@Table(name="Pages") 
public class Page { 

    @Id @GeneratedValue 
    private long id; 

    private String title; 
    private Instant lastRetrieved; 
    private PageCategory category; 
    private URL source; 

    @Lob 
    private String contents; 

    //hashcode, equals, getters & setters omitted 
} 

package me; 

public enum PageCategory { 
    PRODUCT, 
    INFO 
    ; 
} 

回答

6

显然,你不需要处理器插件。只是常规编译器的作品。我评论了整个

<!-- 
<plugin> 
    <groupId>org.bsc.maven</groupId> 
    <artifactId>maven-processor-plugin</artifactId>    
    <version>2.2.4</version> 
    <executions> 
     <execution> 
      <id>process</id> 
      <goals> 
       <goal>process</goal> 
      </goals> 
      <phase>generate-sources</phase> 
      <configuration> 
       <processors> 
        <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> 
       </processors> 
      </configuration> 
     </execution> 
    </executions> 
    <dependencies> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-jpamodelgen</artifactId> 
      <version>4.3.6.Final</version> 
     </dependency> 
    </dependencies> 
</plugin> 
--> 

部分,它工作正常...去图。我的编译器配置为:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.1</version> 
    <configuration> 
     <source>1.8</source> 
     <target>1.8</target> 
    </configuration> 
</plugin> 
+0

什么这里提到的编译时间与运行时优势:http://stackoverflow.com/questions/25014572/advantage-of-using-jpametamodelentityprocessor? – AWhitford 2015-01-13 04:26:49

+0

@AWhitford看起来完全是另一个问题。 – ArtB 2015-01-13 15:14:21

相关问题