reverse engineering hibernate 生成带注解的实体类

来源:互联网 发布:芒种日期算法 编辑:程序博客网 时间:2024/05/21 07:06

安装hibernate-tools插件

1.下载hibernatetools插件

  1. 点击eclipse菜单Help,选择Install New Software...
  1. Work with处:http://download.jboss.org/jbosside/updates/stable
  1. 只选择其中的Hibernate Tool

注意不要选择Contact all update sites during install to find required software,否则会长时间停留在calculating requirementsand dependencies

  1. 点击Next。更新完成后重启eclipse

 

根据数据库逆向生成hibernate的实体类

Data Source Explorer

  1. eclipse中:WindowàShow ViewàOtheràData Source Explorer,ServersConsole窗口同级,出现了Data Source Explorer窗口

  1. 右键Database ConnectionsàNew ..

选择数据库类型,并重命名

  1. 创建数据库连接

增加驱动

添加驱动jar

mysql-connector-java-5.1.0-bin.jar放到资源管理器中的合适位置

 

 

填写数据库连接信息,保存密码,选择完成

 

DataBase Connections的子节点,出现我们刚刚创建的数据库连接

Hibernate Configurations

  1. WindowàShow ViewàOther..àHibernateàHibernate Configurations

ServersConsole同级,出现HibernateConfigurations窗口

  1. 空白处右键 Add Configurations..
  1. 指定projectDatabase connection

Database connection:选择之前的设置好的数据库连接

  1. 新建Propertyfile:Setup.. àCreate new..指定创建的位置到core下的resources

  1. 创建Configuration file: Setup..--> Create new..指定创建的位置到core下的resources

 

执行逆向工程

  1. 自定义视图

WindowàCustomize Perspective..,选择Command Groups Availability,勾选上HibernateCodeGeneration

  1. 选择菜单栏中的

 

 

  1. 创建reveng.xml

Setup..--> Create new..指定位置为core包下的resoureces

选择下一步

  1. 选择finish,回到Hibernate Code Generation Configurations 页面,选择Exporters

  1. 选择Run,在相应的entity包下,出现了相应的实体

0 0