Hibernate最基礎配置的記憶方式

來源:互聯網
上載者:User

標籤:word   驅動   資料   3.0   nec   dial   roo   pre   htm   

配置範本:   http://www.tutorialspoint.com/hibernate/hibernate_configuration.htm

1,核心設定檔

這個設定檔可以結合Hibernate的使用來記憶。

首先,在使用Hibernate的時候,需要先構造Configuration對象,然後用Configuration建造一個SessionFactory的一個具體實現。這就是一個抽象原廠模式。可以這樣來記憶:既然factory的具體資訊都來自configuration,那麼<session-factory>標籤包含在<hibernate-configuration>標籤裡就顯得理所應當了。

其次,<session-factory>標籤下的具體資訊。Hibernate本身是對jdbc的輕量封裝,那麼jdbc介面的資訊出現在<session-factory>標籤裡也就理所應當了。

關於hibernate.dialect。要知道,jdbc只是一個標準,平時對不同的資料庫進行jdbc串連,也要下載對應的jdbc驅動,這是因為不同的資料庫的內部實現不同。至於Dialect,官網描述為Represents a dialect of SQL implemented by a particular RDBMS.(代表了特定關聯式資料庫的sql實現) ,可以猜測dialect做的是關於sql語句的封裝。

最後,實體類對應檔的根節點是<hibernate-mapping>,下面可以配置一到多個<class>標籤,既可以一個實體類對應一個對應檔,也可以把多個實體類映射放在同一個檔案中。

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <property name="hibernate.dialect">            org.hibernate.dialect.MySQLDialect        </property>        <property name="hibernate.connection.driver_class">            com.mysql.jdbc.Driver        </property>        <!-- Assume test is the database name -->        <property name="hibernate.connection.url">            jdbc:mysql://localhost:3306/db1        </property>        <property name="hibernate.connection.username">            root        </property>        <property name="hibernate.connection.password">            pwd        </property>        <!-- List of XML mapping files -->        <mapping resource="tbl1a.hbm.xml" />        <mapping resource="tbl1b.hbm.xml" />    </session-factory></hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC  "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping>    <class name="com.pojo.Tbl1a" table="tbl1a">        <id name="id" type="int" column="id"></id>        <property name="iachar" column="1achar" type="char" />        <property name="iaint" column="1aint" type="int" />    </class>    </hibernate-mapping>

 

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.