hibernate5.1 數(shù)據(jù)庫已建成表生成entity 和 mapping xml
eclipse 版本 Neon 4.6.0 去hibernate 官網(wǎng)下在 hibernate tools 找到對應(yīng)eclipse 適合的版本 下載離線的包 然后使用eclipse的 help->install new software 功安裝 可能hibernate 需求的其他eclipse 版本不適合 所有安裝時(shí) 升級下其他的插件版本 按照提示走就可以了 我安裝完hibernate tools后 eclipse 版本變成了 Neon 4.6.2
安裝完畢后(網(wǎng)絡(luò)不好的話可能要很長時(shí)間) 接著在window ->Show View ->Other 菜單里 找到Hibernate Configurations 打開 會出現(xiàn)一個(gè)Hibernate Configuration 控制臺 然后右擊添加 Add Configuration 進(jìn)入到創(chuàng)建配置文件菜單窗口 在Main tab 頁里 選擇 你的hibernate PRoject Configuration file 選你的hibernate.cfg.xml配置文件 讓后再Options tab頁選擇你的數(shù)據(jù)類型 Database dialect 接著點(diǎn)擊OK 這樣配置就完成了
然后這時(shí)注意在eclipse 綠色運(yùn)行按鈕右側(cè)附近 有個(gè)帶小灰色圖標(biāo)的運(yùn)行按鈕 在下拉小三角中 找到 hibernate code generation configuration 打開code generation 菜單 新建一個(gè)配置 在Main tab 頁里選擇剛剛新建的配置 然后配置生成的目錄 勾選上Reverse engineer from JDBC connection 開始從數(shù)據(jù)庫中逆向生成配置文件 填入生成的包名 Package reveng.xml 選擇Setup.. 創(chuàng)建一新的文件 設(shè)置存放路徑 然后選中下一步 next 配置需要映射導(dǎo)出的數(shù)據(jù)表 點(diǎn)擊右側(cè) refresh 刷新 在 Database schema 選中需要的表 點(diǎn)擊 include.. 選擇完畢后 點(diǎn)擊finish 在 exporters tab頁中 選中 Domain code 和 hibernate XML Mappings 其他的選項(xiàng)根據(jù)需要自行配置 然后點(diǎn)擊 run 代碼和配置文件 會自動生成在輸出目錄下。
新聞熱點(diǎn)
疑難解答
圖片精選