码迷,mamicode.com
首页 > Web开发 > 详细

eclipse通过hibernate tools逆向工程生成hbm.xml和实体类

时间:2017-07-29 18:14:25      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:下拉   plugin   声明   jdb   密码   右上角   catalog   ber   web项目   

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,所以我不太清楚是否必要(今天有点懒了)

eclipse通过hibernate tools逆向工程生成hbm.xml和实体类

标签:下拉   plugin   声明   jdb   密码   右上角   catalog   ber   web项目   

原文地址:http://www.cnblogs.com/kongkongFabian/p/7256937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!