1

注釈付きの Java クラスを取得し、データベースによって異なる DDL を生成するように Maven をセットアップしています。これを行うより良い方法はありますか?リソースフィルタリングの出力を操作するように指示するのではなく(パイプラインの一部として)hbm2ddlプラグインへの入力をフィルタリングできるはずです(最終的なjarからフィルタリングする必要があります)。

hibernate.cfg.xml ファイルをフィルタリングして、ローカル開発者の設定に基づいて環境プロパティを置き換えています。

  <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>

次に、内部開発環境に関連するものを出荷したくないので、プロダクション jar から hibernate.cfg.xml を除外する必要があります。

4

1 に答える 1

1

私はこれと同じ問題を抱えており、これが私がそれを解決した方法です。接続の詳細を保持する別の database.properties ファイルを使用しており、XML ファイルをフィルター処理していません。

この別の database.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>

とにかく役に立てば幸いです....

于 2011-01-04T16:03:46.507 に答える