hibernate3-maven-plugin插件入门

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

配置hibernate3-maven-plugin插件:

<plugin>
                <groupId>org.codehaus.mojogroupId>
                <artifactId>hibernate3-maven-pluginartifactId>
                <version>2.2version>
                
                <configuration>
                    <components>
                        <component>
                            <name>hbm2hbmxmlname>
                            <implementation>jdbcconfigurationimplementation>
                            <outputDirectory>target/generated-resources/hibernateoutputDirectory>
                        component>
                        <component>
                            <name>hbm2javaname>
                            <implementation>jdbcconfigurationimplementation>
                            <outputDirectory>target/generated-sources/hibernateoutputDirectory>
                        component>
                    components>
                    <componentProperties>
                        
                        <revengfile>src/main/resources/reveng.xmlrevengfile>
                        
                        <propertyfile>src/main/resources/hibernate.propertiespropertyfile>
                        
                        <packagename>cn.itcast.bos.pojopackagename>
                        <jdk5>truejdk5>
                        
                        <ejb3>trueejb3>
                    componentProperties>
                configuration>
                <dependencies>
                    <dependency>
                        <groupId>cglibgroupId>
                        <artifactId>cglib-nodepartifactId>
                        <version>2.2.2version>
                    dependency>
                    <dependency>
                        <groupId>com.oraclegroupId>
                        <artifactId>ojdbc14artifactId>
                        <version>${oracle.version}version>
                        <scope>runtimescope>
                    dependency>
                dependencies>
            plugin>


配置Hibernate Tools:

<properties>
        <hibernate-tools.version>3.6.0.CR1hibernate-tools.version>
    properties>

<dependencies>      
        <dependency>
            <groupId>org.hibernategroupId>
            <artifactId>hibernate-toolsartifactId>
            <version>${hibernate-tools.version}version>
        dependency>       
    dependencies>

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

 <dependency>
                <groupId>org.hibernategroupId>
                <artifactId>hibernate-toolsartifactId>
                <version>${hibernate-tools.version}version>
                <exclusions>
                    <exclusion>
                        <artifactId>freemarkerartifactId>
                        <groupId>freemarkergroupId>
                    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的反转引擎中也会生成该文件)




<hibernate-reverse-engineering>
    
    <schema-selection match-table="T_USER" match-schema="MYBOS"/>
    <schema-selection match-table="T_BC_.*" match-schema="MYBOS"/>
    
    <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

你可能感兴趣的:(maven实战)