代码之家  ›  专栏  ›  技术社区  ›  Justin

maven hbm2ddl的简单设置

  •  1
  • Justin  · 技术社区  · 14 年前

    我正在设置maven来获取带注释的java类并生成一些DDL,这些DDL根据数据库的不同而变化。有没有更好的办法?似乎我应该能够过滤hbm2ddl插件的输入(作为管道的一部分),而不是告诉它对资源过滤的输出进行操作(然后我必须过滤掉我的最终jar)。

      <build>
        <filters>
          <filter>${user.home}/datamodel-build.properties</filter>
        </filters>
        <resources><resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource></resources>
      </build>
    

    然后对输出运行hbm2ddl

    <plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>hibernate3-maven-plugin</artifactId>
      ...
     <configuration>
       <componentProperties>
       <configurationfile>target/classes/com/myOrg/datamodel/hibernate.cfg.xml</configurationfile>
    </plugin>
    

    然后我必须过滤掉休眠.cfg.xml因为我不想发布任何与我的内部开发环境相关的东西。

    1 回复  |  直到 14 年前
        1
  •  1
  •   Dave    13 年前

    这是分开的数据库.properties文件被过滤,但由于它是一个 测试 /src/main/test 它不会被放入最后的人工制品中。然后我告诉hbm2ddl在哪里可以找到它,如下所示:

                <configuration>
                    <components>
                        <component>
                            <name>hbm2ddl</name>
                            <implementation>jpaconfiguration</implementation>
                        </component>
                    </components>
                    <componentProperties>
                        <propertyfile>src/test/resources/database.properties</propertyfile>
                        <!-- Gives the name of the persistence unit as defined in persistence.xml -->
                        <persistenceunit>myapp-core</persistenceunit>
                        <!-- Tells the plugin to send the output to a file -->
                        <outputfilename>create-${database.vendor}-schema.sql</outputfilename>
                        <!-- Pretty Format SQL Code -->
                        <format>true</format>
                        <!-- Do not create tables automatically - other plug-ins will handle that -->
                        <export>false</export>
                        <!-- Do not print the DDL to the console -->
                        <console>false</console>
                    </componentProperties>
                </configuration>
    

    希望它能帮上忙。。。。