eclipse通過hibernate tools逆向工程產生hbm.xml和實體類

來源:互聯網
上載者:User

標籤:下拉   plugin   聲明   jdb   密碼   右上方   catalog   ber   web項目   

1.給自己的eclipse添加hibernate tools

plugin添加方式:http://download.jboss.org/jbosstools/updates/stable/kepler/—》  * Abridged JBoss Tools   --》hibernate tools 3.7.1

2.右上方open perspective(視圖菜單)

添加Database Development視圖並開啟

選擇Database Connections 右鍵建立選擇相應資料庫(下面是mysql或者oracle)

選擇資料庫後需要聲明drivers—》

之後需要做三件事:

a.選擇資料庫版本和名稱(下面會使用到)

b.添加jar包

  |--mysql添加mysql核心包mysql-connector-java...

  |--oracle添加oracle核心包ojdbc6_g.jar(我使用的是11g)

c.properties添加相關配置資訊

mysql ::

Connection URL   : jdbc:mysql://localhost:3306/<資料庫名>

Database Name    : 資料庫名

Driver Class     : com.mysql.jdbc.Driver

Password      : 密碼

User ID       : 使用者名稱 

oracle  ::

Catalog         : 不知道有什麼用處

Connection URL   : jdbc:oracle:thin:@localhost:1521:<資料庫名>

Database Name    : 資料庫名

Driver Class     : oracle.jdbc.OracleDriver

Password      : 密碼

User ID       : 使用者名稱

這樣我們就完成了與資料庫之間的串連,我們可以在eclipse直接對資料進行操作了,速度慢

3.回到java視圖

a.建立一個web項目

b.開啟功能表列的window--》Show Views --》開啟Hibernate --》 顯示視圖Hibernate Configurations

c.視圖Hibernate Configurations 右鍵 Add Configuration...

name —— 我們接下來會用到

配置 Type —— hibernate版本

  Project—— 選擇那個項目

  Database connection —— 我們上一步配置的名稱

  Property file —— 建立hibernate.properties

  Configuraction file —— 建立hibernate.cfg.xml(它自身建立的這個檔案少一段配<property name="dialect">org.hibernate.dialect.OracleDialect</property>)

  切換到common

  選擇編碼utf-8

這樣第三步就配置好了

4.我的工具列上有一個Run hibernate.cfg.xml

點擊下拉 --》 Hibernate Code Generation Configurations

建立一個New configuration

Console configuration  —— 選擇上一步配置好的名稱

Output directory —— 選擇匯出的項目名稱

點擊Reverse engineer from JDBC Connection

Package —— 匯出的包

reveng,xml —— 匯出的reveng.xml檔案放到哪

  產生時會進入Configure table filters中

  選擇Console configuration後Refresh(需要等一段時間),然後選擇資料庫或者表進行操作

切換到Exporters

選擇Domain code和 Hibernate XML Mappings

最後點擊Run 就產生了

 

注意:我匯入jar包除了上訴jar包外,還添加了hibernate-core.jar,所以我不太清楚是否必要(今天有點懶了)

eclipse通過hibernate tools逆向工程產生hbm.xml和實體類

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.