Hibernate入門配置案例

來源:互聯網
上載者:User

標籤:use   oracle10g   hbm.xml   url   jdbc   map   方言   隨心所欲   upd   

Hibernate是一個開放原始碼的對象關係映射架構,它對JDBC進行了非常輕量級的對象封裝,它將POJO與資料庫表建立映射關係,是一個全自動的orm架構,hibernate可以自動產生SQL語句,自動執行,使得Java程式員可以隨心所欲的使用對象編程思維來操縱資料庫。 Hibernate可以應用在任何使用JDBC的場合,既可以在Java的用戶端程式使用,也可以在Servlet/JSP的Web應用中使用,最具革命意義的是,Hibernate可以在應用EJB的J2EE架構中取代CMP,完成資料持久化的重任。

1.關於Hibernate需求的jar包

2.配置大配置hibernate.cfg.xml檔案

串連資料庫語句:

<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">wyd</property>
<property name="connection.password">wyd</property>

hibernate方言配置:

<property  name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>             

通知DB的操作

<property name="hbm2ddl.auto">update</property>

關聯小設定檔

<mapping resource="cn/wyd/entity/Student.hbm.xml"/>

3.配置小配置Student.hbm.xml

設定實體類的位置

<hibernate-mapping package="cn.wyd.entity">

設定實體類和DB的資料表的名稱

<class name="Student" table="Student">

 設定資料表的主鍵id以及自增或序列

<id name="id" column="id">
<generator class="native"/>
</id>

 設定其他屬性

<property name="age" column="age"></property>
<property name="name" column="name"></property>

 4.通過添加操作測試hibernate

 

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.