为了以防万一,下面是hibernate3-maven-plugin的工作配置,用于自底向上方法:
<plugin> <groupId>org.prehaus.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.EmbeddedDriverhibernate.connection.url=jdbc:derby:./derbyDBs/EMPLDBhibernate.connection.username=APPhibernate.connection.password=APPhibernate.dialect=org.hibernate.dialect.DerbyDialect#workaround for http://opensource.atlassian.com/projects/hibernate/browse/HBX-1145hibernate.connection.autocommit=true
此设置:
- 生成
*.hbm.xml
在target/classes
(与包)过程中generate-resources
。 - 生成一个
hibernate.cfg.xml
在target/classes
与映射文件中的条目。 - 从中的映射生成实体
target/generated-sources/hibernate3
(我建议遵循target/generated-sources/<tool>
生成资源的约定,以便IDE可以自动检测到它们)。
这是
clean compile针对具有两个表的示例数据库的结果:
$ mvn clean编译...$树目标/目标/├──班级│├──com││└──我的公司││└──myapp││├──Department.class││├──Department.hbm.xml││├──员工等级││└──Employee.hbm.xml│├──database.properties│└──hibernate.cfg.xml└──生成源 └──hibernate3 └──com ──我的公司 └──myapp ├──Department.java └──Employee.java



