自動生成されたhibernate.cfg.xmlファイルの.hbm.xmlファイルをパッケージパスでマッピングする前にMavenを強制する方法を教えてもらえますか?
私の一般的な考え方は、mavenを介してhibernate-toolsを使用して、アプリケーションの永続性レイヤーを生成したいということです。したがって、hibernate.cfg.xmlが必要であり、次にすべてのmy_table_names.hbm.xmlが必要であり、最後にPOJOが生成されます。それでも、 *。hbm.xmlファイルをフォルダーhbm2java
に入れると、目標は機能しませんが、マッピングファイルをテーブル名のみで指定します。src/main/resources/package/path/
hbm2cfgxml
<mapping resource="MyTableName.hbm.xml" />
hbm2cfgxml
したがって、大きな問題は、hibernate.cfg.xmlが次のようになるように構成するにはどうすればよいかということです。
<mapping resource="package/path/MyTableName.hbm.xml" />
私のpom.xmlは、現時点では次のようになっています。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hbm2cfgxml</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2cfgxml</goal>
</goals>
<inherited>false</inherited>
<configuration>
<components>
<component>
<name>hbm2cfgxml</name>
<implemetation>jdbcconfiguration</implementation>
<outputDirectory>src/main/resources/</outputDirectory>
</component>
</components>
<componentProperties>
<packagename>package.path</packageName>
<configurationFile>src/main/resources/hibernate.cfg.xml</configurationFile>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>
そして2番目の質問:実行する前にリソースをターゲットフォルダーにコピーするようにMavenに指示する方法はありますhbm2java
か?現時点で使用しています
mvn clean resources:resources generate-sources
そのためですが、もっと良い方法があるはずです。
助けてくれてありがとう。
アップデート:
@Pascal:ご協力いただきありがとうございます。マッピングへのパスは現在正常に機能していますが、以前は何が悪かったのかわかりません。おそらく、データベース構成の読み取り中にhibernate.cfg.xmlへの書き込みに問題があります(ファイルは更新されますが)。
ファイルhibernate.cfg.xmlを削除し、それをdatabase.propertiesに置き換えて、ゴールhbm2cfgxml
とを実行しましたhbm2hbmxml
。私はまた、それらの目標でoutputDirectory
norをもう使用しません。configurationfile
その結果、ファイルhibernate.cfg.xml
とすべて*.hbm.xml
がデフォルト値であるtarget / hibernate3/generated-mappings/フォルダーに生成されます。hbm2java
次に、次のように目標を更新しました。
<componentProperties>
<packagename>package.name</packagename>
<configurationfile>target/hibernate3/generated-mappings/hibernate.cfg.xml</configurationfile>
</componentProperties>
しかし、私は次のようになります。
[INFO] --- hibernate3-maven-plugin:2.2:hbm2java (hbm2java) @ project.persistence ---
[INFO] using configuration task.
[INFO] Configuration XML file loaded: file:/C:/Documents%20and%20Settings/mmm/workspace/project.persistence/target/hibernate3/generated-mappings/hibernate.cfg.xml
12:15:17,484 INFO org.hibernate.cfg.Configuration - configuring from url: file:/C:/Documents%20and%20Settings/mmm/workspace/project.persistence/target/hibernate3/generated-mappings/hibernate.cfg.xml
12:15:19,046 INFO org.hibernate.cfg.Configuration - Reading mappings from resource : package.name/Messages.hbm.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2java (hbm2java) on project project.persistence: Execution hbm2java of goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2java failed: resource: package/name/Messages.hbm.xml not found
どうすれば対処できますか?もちろん、私は追加することができます:
<outputDirectory>src/main/resources/package/name</outputDirectory>
目標に向かってhbm2hbmxml
いますが、これは最善のアプローチではないと思いますか?生成されたすべてのコードとリソースをsrc/
フォルダーから遠ざける方法はありますか?
このアプローチの目標は、src / main /javaまたは/resourcesフォルダーにソースを生成することではなく、生成されたコードをターゲットフォルダーに保持することだと思います。私はこの観点に概ね同意しているので、最終的にhbm2dao
はプロジェクトを実行してパッケージ化し、ビジネスレイヤーから生成された永続性レイヤーコンポーネントとして使用することを継続したいと思います。これもあなたが意味したことですか?