JPA Hibernate元模型通过maven生成



我遵循了JPA modelgen指南,我能够生成我需要的规范元模型。设置此pom:

<plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-proc:none</compilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.0.6-redhat</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <outputDirectory>target/metamodel</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>target/metamodel</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

生成的源是在指定的目录中正确创建的,我必须手动将其指定为 eclipse 项目类路径中的源才能使用它。当我触发 maven 时,日志显示cannot find symbolduplicate class,我仍然成功构建。所以我的问题是,这是创建元模型的预期/正确行为吗?还是我错过了无花果中的某些东西?谢谢

我也在使用 JPA 元模型生成器,我没有你描述的问题,也许我的配置可以提供帮助,我看到了一些差异,第一个是maven-processor-plugin

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <version>2.1.0</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>1.2.0.Final</version-->
      <version>4.3.4.Final</version>
    </dependency>
  </dependencies>
</plugin>

如您所见,我必须添加hibernate-jpamodelgen作为依赖项和处理器属性。

我不确定是否需要将生成的源目录添加到源路径build-helper-maven-plugin。我没有使用它,它对我有用,但也许是因为我对生成的源使用了默认输出路径。

最新更新