hibernate3-maven-plugin插件入门

1.在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.itcast.bos.pojo</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>


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

另外:注意包冲突问题。可以排除低版本的jar

 <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-tools</artifactId>
                <version>${hibernate-tools.version}</version>
                <exclusions>
                    <exclusion>
                        <artifactId>freemarker</artifactId>
                        <groupId>freemarker</groupId>
                    </exclusion>
                </exclusions>
  </dependency>

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

hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:xe
hibernate.connection.username=test
hibernate.connection.password=test

3.建立和配置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="MYBOS"/>
    <schema-selection match-table="T_BC_.*" match-schema="MYBOS"/>
    <!-- 将MYBOS下的T_BC_DECIDEDZONE表反转生成bc包下的 DecidedZone类,主键策略为uuid-->
    <table name="T_BC_DECIDEDZONE" schema="MYBOS"
        class="cn.itcast.bos.domain.bc.DecidedZone">
        <primary-key>
            <generator class="uuid"></generator>
        </primary-key>
    </table>
    <table name="T_BC_REGION" schema="MYBOS"
        class="cn.itcast.bos.domain.bc.Region">
        <primary-key>
            <generator class="uuid"></generator>
        </primary-key>
    </table>
    <table name="T_BC_STAFF" schema="MYBOS"
        class="cn.itcast.bos.domain.bc.Staff">
        <primary-key>
            <generator class="uuid"></generator>
        </primary-key>
    </table>
    <table name="T_BC_SUBAREA" schema="MYBOS"
        class="cn.itcast.bos.domain.bc.Subarea">
        <primary-key>
            <generator class="uuid"></generator>
        </primary-key>
    </table>
    <table name="T_USER" schema="MYBOS"
        class="cn.itcast.bos.domain.user.User">
        <primary-key>
            <generator class="uuid"></generator>
        </primary-key>
    </table>
</hibernate-reverse-engineering>

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值