reverse engineering hibernate 生成帶註解的實體類

安裝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包下,出現了相應的實體

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章