2 kingerzha KingerZha 于 2017.01.16 22:23 提问

maven 反向生成实体项目问题

想在eclipse里面弄一个maven的反向生成实体工程,配置好之后运行一直不生成实体,运行过程也不报错,运行命令使用的:hibernate3:hbm2java ,配置文件如下:

pom.xml

 <?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>AAAAA</groupId>
        <artifactId>AAAAA</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>AAAAA_PO</groupId>
    <artifactId>AAAAA_PO</artifactId>
    <name>AAAAA_PO</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
    </dependencies>

    <build>
        <finalName>AAAAA_PO</finalName>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.2</version>

                <dependencies>
                    <!-- mysql链接驱动,如果是Oracle的就换成Oracle的驱动 <dependency> <groupId>mysql</groupId> 
                        <artifactId>mysql-connector-java</artifactId> <version>5.1.25</version> </dependency> -->
                    <!-- oracle 链接驱动 -->
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc6</artifactId>
                        <version>11.2.0.1.0</version>
                    </dependency>
                    <dependency>
                        <groupId>cglib</groupId>
                        <artifactId>cglib</artifactId>
                        <version>2.2</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>ejb3-persistence</artifactId>
                        <version>3.3.2.Beta1</version>
                    </dependency>
                </dependencies>

                <!-- 运行命令: mvn hibernate3:hbm2java hibernate3:hbm2hbmxml -->
                <configuration>
                    <components>
                        <!-- 映射文件夹 项目目录下运行命令:mvn hibernate3:hbm2hbmxml -->
                        <component>
                            <name>hbm2hbmxml</name>
                            <implementation>jdbcconfiguration</implementation>
                            <outputDirectory>src/main/java/</outputDirectory>
                        </component>
                        <!-- 实体类 项目目录下运行命令:mvn hibernate3:hbm2java -->
                        <component>
                            <name>hbm2java</name>
                            <outputDirectory>src/main/java/</outputDirectory>
                            <implementation>jdbcconfiguration</implementation>
                        </component>
                    </components>

                    <componentProperties>
                        <!-- 生成指定表名的实体类和映射文件(不配置则生成所有的数据表) -->
                        <revengfile>src/main/resources/reveng/hibernate.reveng.xml</revengfile>
                        <!-- hibernate总配置文件,注意是链接数据库的信息 --> 
                        <configurationfile>src/main/resources/reveng/hibernate.cfg.xml</configurationfile>
                        <!-- 输出的包名 -->
                        <packagename>org</packagename> 
                        <!-- true为注解实体类方式,只需要生成java类即可,false为映射文件和非注解java实体类,结合 -->
                        <ejb3>true</ejb3>
                    </componentProperties>

                    <!-- 1、如果你要生成注解方式的 java文件,就运行 mvn hibernate3:hbm2java 2、如果你要生成 hbm.xml 
                        配合 java 的形式就先把 pom 里面 <ejb3>false</ejb3> 弄成false 然后分别运行 mvn hibernate3:hbm2hbmxml 
                        和 mvn hibernate3:hbm2java -->

                </configuration>

            </plugin>
        </plugins>
    </build>
</project>

hibernate.cfg.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="hibernate.connection.password">fj_inms</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:testOrac</property>
        <property name="hibernate.connection.username">fj_inms</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
    </session-factory>
</hibernate-configuration>

hibernate.reveng.xml

 <?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>

    <table-filter match-name="sys_organization"/>

</hibernate-reverse-engineering>

运行配置

 hibernate3:hbm2java

运行控制台打印

 [INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building AAAAA_PO 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> hibernate3-maven-plugin:2.2:hbm2java (default-cli) > process-resources @ AAAAA_PO >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ AAAAA_PO ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] <<< hibernate3-maven-plugin:2.2:hbm2java (default-cli) < process-resources @ AAAAA_PO <<<
[INFO] 
[INFO] --- hibernate3-maven-plugin:2.2:hbm2java (default-cli) @ AAAAA_PO ---
[INFO] using jdbcconfiguration task.
[INFO] Hibernate 3.3.1.GA
[INFO] hibernate.properties not found
[INFO] Bytecode provider name : javassist
[INFO] using JDK 1.4 java.sql.Timestamp handling
[INFO] Configuration XML file loaded: file:/E:/work/workspace_mars/AAAAA/AAAAA_PO/src/main/resources/reveng/hibernate.cfg.xml
[INFO] configuring from url: file:/E:/work/workspace_mars/AAAAA/AAAAA_PO/src/main/resources/reveng/hibernate.cfg.xml
[INFO] Configured SessionFactory: null
[INFO] No hibernate properties file loaded.
[INFO] Override file: E:\work\workspace_mars\AAAAA\AAAAA_PO\src\main\resources\reveng\hibernate.reveng.xml
[INFO] Using Hibernate built-in connection pool (not for production use!)
[INFO] Hibernate connection pool size: 20
[INFO] autocommit mode: false
[INFO] using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:@127.0.0.1:1521:testOrac
[INFO] connection properties: {user=fj_inms, password=****}
[INFO] RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[INFO] JDBC driver: Oracle JDBC driver, version: 11.2.0.1.0
[INFO] Using dialect: org.hibernate.dialect.Oracle10gDialect
[INFO] Using default transaction strategy (direct JDBC transactions)
[INFO] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[INFO] Automatic flush during beforeCompletion(): disabled
[INFO] Automatic session close at end of transaction: disabled
[INFO] JDBC batch size: 15
[INFO] JDBC batch updates for versioned data: disabled
[INFO] Scrollable result sets: enabled
[INFO] JDBC3 getGeneratedKeys(): disabled
[INFO] Connection release mode: auto
[INFO] Default batch fetch size: 1
[INFO] Generate SQL with comments: disabled
[INFO] Order SQL updates by primary key: disabled
[INFO] Order SQL inserts for batching: disabled
[INFO] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[INFO] Using ASTQueryTranslatorFactory
[INFO] Query language substitutions: {}
[INFO] JPA-QL strict compliance: disabled
[INFO] Second-level cache: enabled
[INFO] Query cache: disabled
[INFO] Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
[INFO] Optimize cache for minimal puts: disabled
[INFO] Structured second-level cache entries: disabled
[INFO] Statistics: disabled
[INFO] Deleted entity synthetic identifier rollback: disabled
[INFO] Default entity-mode: pojo
[INFO] Named query checking : enabled
[INFO] cleaning up connection pool: jdbc:oracle:thin:@127.0.0.1:1521:testOrac
[INFO] Hibernate Tools 3.2.2.GA
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.482 s
[INFO] Finished at: 2017-01-16T22:12:45+08:00
[INFO] Final Memory: 18M/246M
[INFO] ------------------------------------------------------------------------
[INFO] cleaning up connection pool: jdbc:oracle:thin:@127.0.0.1:1521:testOrac

2个回答

KingerZha
KingerZha   2017.01.17 16:04
已采纳

解决:
注意问题:
1、hibernate.cfg.xml配置文件中,schema使用大写,否则会出现不识别问题,如:
FJ_INMS

2、如果做单个表的反向生成,配置hibernate.reveng.xml文件时,表名需要大写,否则不识别

zzhao114
zzhao114   2017.02.10 15:44

楼主有maven反向工程的教程的博文么?谢谢谢谢

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
maven反射生成实体类
关于使用maven hibernate Plugin 生成java实体类使用 maven hibernate Plugin 主要有6种功能 • hibernate3:hbm2cfgxml: Generates hibernate.cfg.xml • hibernate3:hbm2ddl: Generates database schema. • hibernate3: hbm2d
maven反向生产对应的实体类
mybatis-generator有三种用法:命令行、eclipse插件、maven插件。个人觉得maven插件最方便,可以在eclipse/intellij idea等ide上可以通用。 一、在pom.xml中添加plugin [html] view plain copy xml version="1.0" encod
Maven 配置mybatis反向生成
配置pom.xml  新建Maven项目,在pom.xml文件中配置 org.mybatis.generator mybatis-generator-maven-plugin 1.3.2 true true
eclipse用Hibernate3-maven-plugin插件反转生成实体类
eclipse用Hibernate3-maven-plugin插件反转生成实体类
maven根据工程生成archetype,并反向生成工程
构建并发布archetype         1.添加archetype的插件                                  org.apache.maven.pluginsgroupId>             maven-archetype-pluginartifactId>             2.2version>         plugin>
MyEclipse----从数据库反向生成实体类之JPA方式
最近开发项目涉及到的表太多,一个一个的写JAVA实体类很是费事, 一个类少说写下来加注释也得几分钟,上百个类的就不得了了,踌躇之际,经理告诉我有简便的方法就是方向数据库了,看着他做了一遍感觉太棒了,没想到 MyEclipse尽然这么强大,赶紧记录下来又学到的知识。 步骤大致如下:  window-->open Perspective-->MyEclipse Java Persistence
mybatis逆向生成实体类,maven方式
1.pom文件 虽然pom文件中的&amp;lt;dependency&amp;gt;依赖中已经有了mysql驱动包,但在 &amp;lt;plugin&amp;gt;插件中,必须再引入mysql-connector-java,再加上mybatis-generator-core和mybatis包.。由于原先的pom文件中有spring-boot-maven-plugin插件(springboot项目),所以用&amp;lt;plugi...
通过数据库自动反向生成MyBatis文件
做一个项目、如果选择MyBatis框架的话,少不了写xml、dao、model。 Mybatis虽好、但是表多了的话、就要重复写xml、dao、model,对于程序猿来说这工作完全就是ctrl + c,ctrl + V ,在这方面的操作就浪费了大把时间。 于是出现了自动生成工具,这工具会通过数据库自动反向生成对应的dao,model,xml,能够大大提示开发效率。
IDEA ---- mybatis ---- 逆向生成实体类
首先,这是我的项目结构: 数据库 4 张表: 1、先引入 jar:<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
eclipse使用jpa实现数据库反向生成Hibernate实体
为了避免实体创建时的手误,并且节约事件,我建议实体类的生成最好使用jpa反向生成。 1.使eclipse连通数据库 a.打开eclipse中的数据库资源 b.新建一个数据库连接  右键点击Database Connections——>new c.选择数据库类型,并为新建的连接命名。 d.点击next进行连接设置 如果Drivers为空,点击上图按钮进行设置,不