Hibernate學習——映射關係

來源:互聯網
上載者:User

標籤:

學習記錄 O(∩_∩)O 、 如果你恰巧路過,希望你能停下腳步瞧一瞧,不足之處望指出,感激不盡~

使用工具:

  1、eclipse   2、hibernate壓縮包(hibernate_4.3.11) 3、mysql

  準備工作: 建立工程——>匯入hibernate.jar包——>編寫 hibernate.cfg.xml 設定檔 串連資料庫

    

   編寫一個類讀取hibernate.cfg.xml

 

一、單向一對多(例子:一個部門有多個員工)

    1、建表(Employee員工表和dpet部門表)

       ①Employee類

  

 ② 配置Employee.hbm.xml 對應檔,並在hibernate.cfg.xml檔案中註冊( <mapping resource="com/sw/entity/Employee.hbm.xml"/>)

    ③ Dept類

 

  ④ Dept.hbm.xml設定檔,並在hibernate.cfg.xml檔案中註冊( <mapping resource="com/sw/entity/Dept.hbm.xml"/>)

  ⑤、建立表方法

 

2、添加資料:
先添加多端資料,再添加一端資料,再讓多端中的資料與一端資料進行關聯,在資料庫中,會先執行insert語句,再執行update語句修改關聯關係,效率偏低

 

 

Hibernate學習——映射關係

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.