安裝hibernate-tools插件
1.下載hibernatetools插件
- 點擊eclipse菜單Help,選擇Install New Software...
- 只選擇其中的Hibernate Tool
注意不要選擇Contact all update sites during install to find required software,否則會長時間停留在calculating requirementsand dependencies
- 點擊Next。更新完成後重啓eclipse。
根據數據庫逆向生成hibernate的實體類
Data Source Explorer
- 在eclipse中:WindowàShow ViewàOtheràData Source Explorer,與Servers和Console窗口同級,出現了Data Source Explorer窗口
- 右鍵Database ConnectionsàNew ..
選擇數據庫類型,並重命名
- 創建數據庫連接
增加驅動
添加驅動jar包
將mysql-connector-java-5.1.0-bin.jar放到資源管理器中的合適位置
填寫數據庫連接信息,保存密碼,選擇完成
DataBase Connections的子節點,出現我們剛剛創建的數據庫連接
Hibernate Configurations
- WindowàShow ViewàOther..àHibernateàHibernate Configurations
與Servers和Console同級,出現HibernateConfigurations窗口
- 空白處右鍵 Add Configurations..
- 指定project和Database connection
Database connection:選擇之前的設置好的數據庫連接
- 新建Propertyfile:Setup.. àCreate new..指定創建的位置到core下的resources下
- 創建Configuration file: Setup..--> Create new..指定創建的位置到core下的resources下
執行逆向工程
- 自定義視圖
WindowàCustomize Perspective..,選擇Command Groups Availability,勾選上HibernateCodeGeneration
- 選擇菜單欄中的
- 創建reveng.xml
Setup..--> Create new..指定位置爲core包下的resoureces
選擇下一步
- 選擇finish,回到Hibernate Code Generation Configurations 頁面,選擇Exporters
- 選擇Run,在相應的entity包下,出現了相應的實體