eclipse 配置hibernate自動生成工具
Hibernate Tools Eclipse 外掛安裝
Hibernate Tools 簡介:Hibernate Tools是由JBoss推出的一個Eclipse綜合開發工具外掛,該外掛可以簡化ORM框架Hibernate,以及JBoss Seam,EJB3等的開發工作。Hibernate Tools可以以Ant Task以及Eclipse外掛的形式執行。
Mapping Editor(對映檔案編輯器):該編輯器可以用來編輯Hibernate XML對映檔案,提供程式碼自動補全,語法高亮功能。
- 類名的自動補全
- 屬性/表的列名自動補全
Hibernate Console(Hibernate控制檯):它提供一個全新的Eclipse Perspective視窗,可以執行HQL,並檢視查詢的結果。這是一個非常便利的工具,可以用來驗證HQL的語法是否正確。
Configuration Wizards and Code generation(Hibernate配置檔案hibernate.cfg.xml建立導航,以及程式碼生成器):支 持完全反向生成功能,可以從已有的資料庫生成Hibernate配置檔案hibernate.cfg.xml,同時支援"click-and- generate"方式生成Java程式碼(Hibernate POJOs),DAO,XML對映檔案(.hbm.xml),以及schema 文件(.hml)等檔案。
Eclipse JDT integration(程式碼補全):該工具支援Java程式碼中的HQL輸入補全,以及對Java程式碼中的HQL語法加以合法性驗證。
下面是Hibernate Tools的相關使用及配置:
1.到Hibernate的官網上下載
HibernateTools-3.2.4.GA-R200905070146-H18.zip
2.解壓下載的檔案,可以得到兩個資料夾features和plugins,把這兩個資料夾裡邊的東西分別考貝到Eclipse的features和plugins下。
3.驗證一下是不是安裝好了。選擇工程下的SRC目錄,然後右鍵New->Other->Hibernate
看到以下內容就說明安裝成功了
4.現在我們可以選擇其中的某一項來使用了。先建一個hibernate.cfg.xml吧。如圖:
自動建立的檔案內容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
- </session-factory>
- </hibernate-configuration>
在這個基礎上,我們可以自行新增我們需要的property和mapping。
下面是一個相對比較完整的版本:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <!-- Database Connection Settings -->
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/UniversityDatabase</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.connection.password"></property>
- <property name="hibernate.default_schema">UniversityDatabase</property>
- <!-- SQL dialect -->
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
- <!-- JDBC connection pool (use the built-in) -->
- <property name="connection.pool_size">1</property>
- <!-- Enable Hibernate's automatic session context management -->
- <property name="current_session_context_class">thread</property>
- <!-- Disable the second-level cache -->
- <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
- <!-- Echo all executed SQL to stdout -->
- <property name="show_sql">true</property>
- <mapping resource="User.hbm.xml" />
- <mapping resource="Course.hbm.xml" />
- <mapping resource="Employee.hbm.xml" />
- </session-factory>
- </hibernate-configuration>
5.建一個Hibernate Console Configuration,這裡需要給Configuration起個名字,Project專案中選擇當前工程,然後Datasbase Connection選擇連線的資料庫,單擊OK。如圖:
如果成功的話,會在Hibernate的控制檯看到資料庫中的Table列表,如圖:
6.新建hibernate.reveng.xml
new->others->hibernate->Hibernate Reverse Engineering File到了以下畫面:選擇console configuration,點選refresh,選中需要Reverse的Table,點選include。最後finish就好了。
生成的XML如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
- <hibernate-reverse-engineering>
- <table-filter match-catalog="UniversityDatabase" match-name="admin"/>
- <table-filter match-catalog="UniversityDatabase" match-name="course"/>
- <table-filter match-catalog="UniversityDatabase" match-name="department"/>
- <table-filter match-catalog="UniversityDatabase" match-name="employee"/>
- <table-filter match-catalog="UniversityDatabase" match-name="employeeaddresses"/>
- <table-filter match-catalog="UniversityDatabase" match-name="employeecertification"/>
- <table-filter match-catalog="UniversityDatabase" match-name="employeeeducations"/>
- <table-filter match-catalog="UniversityDatabase" match-name="employeehours"/>
- <table-filter match-catalog="UniversityDatabase" match-name="employeememo"/>
- <table-filter match-catalog="UniversityDatabase" match-name="externalcourse"/>
- <table-filter match-catalog="UniversityDatabase" match-name="internalcourse"/>
- <table-filter match-catalog="UniversityDatabase" match-name="person"/>
- <table-filter match-catalog="UniversityDatabase" match-name="project"/>
- <table-filter match-catalog="UniversityDatabase" match-name="resourceassignment"/>
- <table-filter match-catalog="UniversityDatabase" match-name="student"/>
- <table-filter match-catalog="UniversityDatabase" match-name="user"/>
- <table-filter match-catalog="UniversityDatabase" match-name="usercourses"/>
- </hibernate-reverse-engineering>
相關文章
- Hibernate之自動生成工具
- eclipse配置程式碼自動提示Eclipse
- Eclipse中設定自動生成的author,date等註釋Eclipse
- 在Eclipse 下整合ndk 自動編譯生成so檔案Eclipse編譯
- [轉]eclipse藉助hibernate tool從資料庫逆向生成Hibernate實體類Eclipse資料庫
- Eclipse自動補全功能和自動生成作者、日期註釋等功能設定Eclipse
- 使用shell生成orabbix自動化配置指令碼指令碼
- 簡書自動生成目錄小工具
- 【楊航】自動生成實體類工具原始碼原始碼
- Hibernate查詢自動更新
- Eclipse設定XML檔案的自動格式化配置EclipseXML
- 【Flutter工具】fmaker:自動生成倍率切圖/自動更換App圖示FlutterAPP
- 使用API自動生成工具優化前端工作流API優化前端
- [討論]J2EE專案自動生成工具
- 客戶端自動配置安裝(expect工具)客戶端
- uuid自動生成UI
- xorm自動生成modelORM
- 自動生成屬性
- 網站自動生成?網站
- 自動做遊戲(3):行走圖生成工具開放試用遊戲
- 自動化檔案目錄結構生成工具——filemap.jsJS
- Fastlane自動打包工具build號自增處理配置方法ASTUI
- eclipse 手動/自動安裝外掛Eclipse
- eclipse 生成APKEclipseAPK
- AOS 自動生成程式碼(三) Service生成
- eclipse使用mybatis generator自動生成程式碼報錯Generation Warnings Occured Project E: doesEclipseMyBatisProject
- eclipse+hibernate 連線Oracle (-)EclipseOracle
- 求助hibernate+eclipse問題Eclipse
- 自動生成操作slice的程式碼工具(unique,map,concate等)
- BigCode:使用AI自動生成程式碼的開源工具GCAI開源工具
- Vue-Layout:視覺化佈局、自動生成程式碼工具Vue視覺化
- showdoc 自動生成 API 文件API
- 【譯】自動生成整型序列
- 自動生成serialVersionUIDUI
- DRF 自動生成介面文件
- 自動生成介面文件coreapiAPI
- dva-boot[-X] React相關工程自動配置工具bootReact
- Ansible :一個配置管理和IT自動化工具