hbm2javaとhbm2daoを構成する方法生成クラスにpackagenameを追加する
-
27-09-2019 - |
質問
設定しようとしています hbm2java
MavenでPojoクラスとDAOオブジェクトを生成します。私が扱っている問題の1つは、パッケージ名が生成されないことです。私はそのために次のPOMを使用しています:
<execution>
<id>hbm2java</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<inherited>false</inherited>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
</component>
</components>
<componentProperties>
<packagename>package.name</packagename>
<configurationfile>target/hibernate3/generated-mappings/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
</execution>
しかし、生成されたコードは次のものから始まります。
// default package
// Generated 2010-05-17 13:11:51 by Hibernate Tools 3.2.2.GA
/**
* Messages generated by hbm2java
*/
public class Messages implements java.io.Serializable {
メイベンに生成を強制する方法はありますか パッケージ で定義されている部分 パッケージ名?
アップデート:
これが私のhibernate.cfg.xmlです。また、Hibernate-Tools(HBM2CFGXML)によって自動的に生成されます。
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/db</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<mapping resource="package/name/Messages.hbm.xml" />
</session-factory>
</hibernate-configuration>
解決
念のため、ボトムアップアプローチのためのHibernate3-Maven-Pluginの動作構成を次に示します。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-xml-files</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2hbmxml</goal>
<goal>hbm2cfgxml</goal>
</goals>
</execution>
<execution>
<id>generate-entities</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
</execution>
</executions>
<configuration>
<components>
<component>
<name>hbm2hbmxml</name>
<implementation>jdbcconfiguration</implementation>
<outputDirectory>target/classes</outputDirectory>
</component>
<component>
<name>hbm2cfgxml</name>
<implementation>jdbcconfiguration</implementation>
<outputDirectory>target/classes</outputDirectory>
</component>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
<outputDirectory>target/generated-sources/hibernate3</outputDirectory>
</component>
</components>
<componentProperties>
<propertyfile>src/main/resources/database.properties</propertyfile>
<jdk5>true</jdk5>
<ejb3>false</ejb3>
<packagename>com.mycompany.myapp</packagename>
<format>true</format>
<haltonerror>true</haltonerror>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.5.3.0_1</version>
</dependency>
</dependencies>
</plugin>
そして、これが私の内容です src/main/database.properties
ファイル:
hibernate.connection.driver_class=org.apache.derby.jdbc.EmbeddedDriver
hibernate.connection.url=jdbc:derby:./derbyDBs/EMPLDB
hibernate.connection.username=APP
hibernate.connection.password=APP
hibernate.dialect=org.hibernate.dialect.DerbyDialect
#workaround for http://opensource.atlassian.com/projects/hibernate/browse/HBX-1145
hibernate.connection.autocommit=true
このセットアップ:
- 生成します
*.hbm.xml
のtarget/classes
(パッケージ付き)中generate-resources
. - aを生成します
hibernate.cfg.xml
のtarget/classes
マッピングファイルのエントリ付き。 - マッピングからエンティティを生成します
target/generated-sources/hibernate3
(フォローすることをお勧めしますtarget/generated-sources/<tool>
IDESによって自動検出されるように、生成されたソースの慣習)。
これが結果です clean compile
2つのテーブルを持つサンプルデータベースに対して:
$ mvn clean compile ... $ tree target/ target/ ├── classes │ ├── com │ │ └── mycompany │ │ └── myapp │ │ ├── Department.class │ │ ├── Department.hbm.xml │ │ ├── Employee.class │ │ └── Employee.hbm.xml │ ├── database.properties │ └── hibernate.cfg.xml └── generated-sources └── hibernate3 └── com └── mycompany └── myapp ├── Department.java └── Employee.java
他のヒント
わかりました、私はそれを理解しました。答えを出しました ここ.
所属していません StackOverflow