MAVEN HIBERNATE3 PLUGIN的使用

首先看官方文档

<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>jdbcconfiguration</implementation>
</component>
<component>
<name>hbm2hbmxml</name>
<outputDirectory>src/main/resources</outputDirectory>
</component>
</components>
<componentProperties>
<drop>true</drop>
<configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>jdbc.artifact.groupid</groupId>
<artifactId>jdbc-driver</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...

</project>



运用官方文档可以直接应用,不过在运用hibernate3:hbm2cfgxml中,命令会查找数据库中所有库表,达不到我们日常
的 需求,需要特定对应某些表的生成时,需要添加文件hibernate.reveng.xml,放入src/main/resources文件夹下

内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering
SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<!--<schema-selection match-schema="TMDCS"/>-->
<table-filter match-schema="TMDCS" match-name="TMDCS_TASK.*"/>
<table-filter match-schema="TMDCS" match-name="TMDCS_DRV_TEMP"/>
<!--<table-filter match-schema=".*" match-name=".*" exclude="true"/>-->
</hibernate-reverse-engineering>

POM.XML文件中需要添加
<revengfile>src/main/resources/hibernate.reveng.xml</revengfile>

在运行命令时,大部分都会遇到类似的错误
[INFO] ------------------------------------------------------------------------ 
[ERROR] FATAL ERROR 
[INFO] ------------------------------------------------------------------------ 
[INFO] net/sf/cglib/core/KeyFactory 
net.sf.cglib.core.KeyFactory 
[INFO] ------------------------------------------------------------------------ 
[INFO] Trace 
java.lang.NoClassDefFoundError: net/sf/cglib/core/KeyFactory 
        at org.hibernate.cfg.reveng.OverrideRepository.<clinit>(OverrideRepository.java:551) 
        at org.codehaus.mojo.hibernate3 .configuration.JDBCComponentConfiguration.loadRevengFile(JDBCComponentConfiguration.java:75) 
        at org.codehaus.mojo.hibernate3 .configuration.JDBCComponentConfiguration.doConfiguration(JDBCComponentConfiguration.java:40) 
        at org.codehaus.mojo.hibernate3 .configuration.AbstractComponentConfiguration.getConfiguration(AbstractComponentConfiguration.java:56) 
        at org.codehaus.mojo.hibernate3 .HibernateExporterMojo.configureExporter(HibernateExporterMojo.java:200) 
        at org.codehaus.mojo.hibernate3 .exporter.Hbm2JavaGeneratorMojo.configureExporter(Hbm2JavaGeneratorMojo.java:64)

net/sf/cglib/core/KeyFactory 却是在我们的依赖关系中的

解决方法如下
将HIBERNATE的基本 的
                  <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc14</artifactId>
                        <version>10.2.0.2.0</version>
                    </dependency>
                      ..........

放入<PLUGIN></PLUGIN> 之中就可以解决


范例:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>hibernate-test</groupId>
    <artifactId>hibernate-test</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>hibernate-test</name>
    <url>http://maven.apache.org</url>
    <build>
        <finalName>irss</finalName>
        <plugins>
           <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <!--hibernate插件-->
            <plugin>

                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.2</version>

                <configuration>
                    <components>
                        <component>
                            <name>hbm2ddl</name>
                            <implementation>jdbcconfiguration</implementation>
                        </component>
                        <component>
                            <name>hbm2cfgxml</name>
                            <!--<outputDirectory>target/hibernate3/generated-mappings</outputDirectory>-->
                            <outputDirectory>src/main/resources/</outputDirectory>
                        </component>
                        <component>
                            <name>hbm2hbmxml</name>
                            <!--<outputDirectory>target/hibernate3/generated-mappings</outputDirectory>-->
                            <outputDirectory>src/main/resources/</outputDirectory>
                        </component>
                        <component>
                            <name>hbm2java</name>
                            <!--<outputDirectory>target/hibernate3/generated-sources</outputDirectory>-->
                            <outputDirectory>src/main/java</outputDirectory>
                        </component>
                        <component>
                            <name>hbm2dao</name>
                            <outputDirectory>target/hibernate3/generated-sources</outputDirectory>
                            <!--<outputDirectory>src/main/java/org/cn/hibernate/dao</outputDirectory>-->
                        </component>
                    </components>
                    <componentProperties>
                        <drop>true</drop>
                        <jdk5>true</jdk5>
                        <packagename>org.cn.hibernate.model</packagename>
                        <configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
                        <propertyfile>src/main/resources/jdbc.properties</propertyfile>
                        <revengfile>src/main/resources/hibernate.reveng.xml</revengfile>
                    </componentProperties>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc14</artifactId>
                        <version>10.2.0.2.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate</artifactId>
                        <version>3.2.6.ga</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-annotations</artifactId>
                        <version>3.3.1.GA</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.transaction</groupId>
                        <artifactId>jta</artifactId>
                        <version>1.1</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.activation</groupId>
                        <artifactId>activation</artifactId>
                        <version>1.1.1</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>

    </build>
</project>

这样,就可以灵活运用了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值