首页 > 学院 > 开发设计 > 正文

eclipse用Hibernate3-maven-plugin插件反转生成实体类

2019-11-08 01:32:08
字体:
来源:转载
供稿:网友

根据数据表生成实体和映射

Hibernate Tools插件

Hibernate Tools是Hibernate官方提供的。该插件要安装跟Eclipse的版本有关系。反转引擎是插件的功能之一。

Hibernate3-maven-plugin插件

插件配置和使用的步骤:

1.引入和配置hibernate3-maven-plugin插件

a. 在pom.xml中引入和配置hibernate3-maven-plugin插件,并引入Hibernate Tools的依赖项目。 配置hibernate3-maven-plugin插件:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>2.2</version> <!-- <groupId>com.dayatang.maven.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>2.9</version> --> <configuration> <components> <component> <name>hbm2hbmxml</name> <implementation>jdbcconfiguration</implementation> <outputDirectory>target/generated-resources/hibernate</outputDirectory> </component> <component> <name>hbm2java</name> <implementation>jdbcconfiguration</implementation> <outputDirectory>target/generated-sources/hibernate</outputDirectory> </component> </components> <componentPRoperties> <!-- 反转规则配置文件 --> <revengfile>src/main/resources/reveng.xml</revengfile> <!-- Hibernate数据库连接属性文件 --> <propertyfile>src/main/resources/hibernate.properties</propertyfile> <!-- 生成实体类默认包 --> <packagename>cn.aric.bos.domain</packagename> <jdk5>true</jdk5> <!-- 如果设置为true则生成JPA注解,若设置为false则生成hbml.xml --> <ejb3>true</ejb3> </componentProperties> </configuration> <dependencies> <dependency> <groupId>cglib</groupId> <artifactId>cglib-nodep</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>com.Oracle</groupId> <artifactId>ojdbc14</artifactId> <version>${oracle.version}</version> <scope>runtime</scope> </dependency> </dependencies> </plugin>

b. hibernate3-maven-plugin插件底层需要依赖于Hibernate Tools。 注意包冲突问题,可以排除低版本的jar。配置Hibernate Tools:

<properties> <hibernate-tools.version>3.6.0.CR1</hibernate-tools.version> </properties> <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-tools</artifactId> <version>${hibernate-tools.version}</version> </dependency> </dependencies>

2.建立和配置src/main/resources/hibernate.properties文件(hibernate核心属性配置)

hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:study hibernate.connection.username=BOS hibernate.connection.passWord=bos

3.建立和配置src/main/resources/reveng.xml文件

建立和配置src/main/resources/reveng.xml文件(反转规则文件,独立规则语法,myeclipse的反转引擎中也会生成该文件)。注意:方案名和表名必须大写!否则无法反转成功!

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" > <hibernate-reverse-engineering> <!--match-schema:匹配(要反转的)方案名(用户名), match-table:匹配表名(支持正则表达式,.*:任意字符串) --> <schema-selection match-table="T_USER" match-schema="BOS"/> <schema-selection match-table="T_BC_.*" match-schema="BOS"/> <!-- 将BOS下的T_BC_DECIDEDZONE表反转生成bc包下的 DecidedZone类,主键策略为uuid--> <table name="T_BC_DECIDEDZONE" schema="BOS" class="cn.aric.bos.domain.bc.DecidedZone"> <primary-key> <generator class="uuid"></generator> </primary-key> </table> <table name="T_BC_REGION" schema="BOS" class="cn.aric.bos.domain.bc.Region"> <primary-key> <generator class="uuid"></generator> </primary-key> </table> <table name="T_BC_STAFF" schema="BOS" class="cn.aric.bos.domain.bc.Staff"> <primary-key> <generator class="uuid"></generator> </primary-key> </table> <table name="T_BC_SUBAREA" schema="BOS" class="cn.aric.bos.domain.bc.Subarea"> <primary-key> <generator class="uuid"></generator> </primary-key> </table> <table name="T_USER" schema="BOS" class="cn.aric.bos.domain.user.User"> <primary-key> <generator class="uuid"></generator> </primary-key> </table> </hibernate-reverse-engineering>

4. 执行maven命令:mvn hibernate3:hbm2java


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表