zoukankan      html  css  js  c++  java
  • eclipse通过hibernate tools逆向工程生成hbm.xml和实体类

    1.给自己的eclipse添加hibernate tools

    plugin添加方式:http://download.jboss.org/jbosstools/updates/stable/kepler/—》  * Abridged JBoss Tools   --》hibernate tools 3.7.1

    2.右上角open perspective(视图菜单)

    添加Database Development视图并打开

    选择Database Connections 右键新建选择相应数据库(下面是mysql或者oracle)

    选择数据库后需要声明drivers—》

    之后需要做三件事:

    a.选择数据库版本和名称(下面会使用到)

    b.添加jar包

      |--mysql添加mysql核心包mysql-connector-java...

      |--oracle添加oracle核心包ojdbc6_g.jar(我使用的是11g)

    c.properties添加相关配置信息

    mysql ::

    Connection URL   : jdbc:mysql://localhost:3306/<数据库名>

    Database Name    : 数据库名

    Driver Class     : com.mysql.jdbc.Driver

    Password      : 密码

    User ID       : 用户名 

    oracle  ::

    Catalog         : 不知道有什么用处

    Connection URL   : jdbc:oracle:thin:@localhost:1521:<数据库名>

    Database Name    : 数据库名

    Driver Class     : oracle.jdbc.OracleDriver

    Password      : 密码

    User ID       : 用户名

    这样我们就完成了与数据库之间的连接,我们可以在eclipse直接对数据进行操作了,速度慢

    3.回到java视图

    a.创建一个web项目

    b.打开菜单栏的window--》Show Views --》打开Hibernate --》 显示视图Hibernate Configurations

    c.视图Hibernate Configurations 右键 Add Configuration...

    name —— 我们接下来会用到

    配置 Type —— hibernate版本

      Project—— 选择那个项目

      Database connection —— 我们上一步配置的名称

      Property file —— 创建hibernate.properties

      Configuraction file —— 创建hibernate.cfg.xml(它自身创建的这个文件少一段配<property name="dialect">org.hibernate.dialect.OracleDialect</property>)

      切换到common

      选择编码utf-8

    这样第三步就配置好了

    4.我的工具栏上有一个Run hibernate.cfg.xml

    点击下拉 --》 Hibernate Code Generation Configurations

    新建一个New configuration

    Console configuration  —— 选择上一步配置好的名称

    Output directory —— 选择导出的项目名称

    点击Reverse engineer from JDBC Connection

    Package —— 导出的包

    reveng,xml —— 导出的reveng.xml文件放到哪

      生成时会进入Configure table filters中

      选择Console configuration后Refresh(需要等一段时间),然后选择数据库或者表进行操作

    切换到Exporters

    选择Domain code和 Hibernate XML Mappings

    最后点击Run 就生成了

    注意:我导入jar包除了上诉jar包外,还添加了hibernate-core.jar,所以我不太清楚是否必要(今天有点懒了)

  • 相关阅读:
    MATLAB批量打印输出600PPI的图像且图像不留空白
    IC设计基础
    深度学习及图像处理学习路线(一)
    IC设计学习路线
    图像处理算法的仿真平台之VGA时序
    数字IC笔试题芯源
    C++图像处理算法入门前言
    爱因斯坦我的信仰
    linux 设置定时任务执行清理日志脚本
    SpringMVC的工作原理(执行流程)
  • 原文地址:https://www.cnblogs.com/kongkongFabian/p/7256937.html
Copyright © 2011-2022 走看看