JPA Meta模型 - 最佳实践

时间:2017-06-20 20:39:27

标签: eclipse hibernate maven jpa

我刚配置Maven来生成我的Hibernate JPA元模型,但现在我对如何管理它有疑问。使用元模型类的最佳实践是什么?

  1. 在src文件夹中生成
  2. 将其保存在target/generated-sources/annotations(Maven自动执行)
  3. 如果#2是最佳选择,在导入Maven项目时如何将其添加到Eclipse构建路径?我想自动完成,无需配置每个项目。

    更新(21/06/2016)

    根据Michele的建议,我更新并找到了可行的解决方案。

    1)要生成元模型,只需将此依赖项添加到:

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>1.2.0.Final</version>
        </dependency>
    

    2)将此插件添加到pom.xml

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated-sources/annotations/</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    

0 个答案:

没有答案