【问题标题】:JPA Hibernate Metamodel generation through maven通过 maven 生成 JPA Hibernate 元模型
【发布时间】:2012-05-10 05:59:25
【问题描述】:

我遵循 JPA modelgen guide 并且能够生成我需要的规范元模型。有了这个 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 并且我仍然可以成功构建。所以我的问题是,这是创建元模型的预期/正确行为吗?还是我错过了 cofig 中的某些内容?谢谢

【问题讨论】:

标签: hibernate jpa


【解决方案1】:

我也在使用JPA Metamodel生成器,没有你描述的问题,也许我的配置可以帮助,我看到了一些不同,第一个是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 是否需要将生成源的目录添加到您的源路径。我没有使用它,它对我有用,但可能是因为我使用生成源的默认输出路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    • 2021-12-22
    • 2020-03-06
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    相关资源
    最近更新 更多