hibernate的常用配置

來源:互聯網
上載者:User

標籤:

hibernate.cfg.xml的一些相關配置

 

<!DOCTYPE hibernate-configuration PUBLIC    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <!-- 通常,一個session-factory節點代表一個資料庫 -->    <session-factory>            <!-- 1. 資料庫連接配置 -->        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>        <property name="hibernate.connection.url">jdbc:mysql:///hib_demo</property>        <property name="hibernate.connection.username">root</property>        <property name="hibernate.connection.password">root</property>        <!-- 資料庫方法配置, hibernate在啟動並執行時候,會根據不同的方言產生符合當前資料庫文法的sql-->        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>        <!-- 2. 其他相關配置 -->        <!-- 2.1 顯示hibernate在運行時候執行的sql語句 -->        <property name="hibernate.show_sql">true</property>        <!-- 2.2 格式化sql -->        <property name="hibernate.format_sql">true</property>          <!-- 2.3 自動建表  -->        <property name="hibernate.hbm2ddl.auto">update</property>                <!-- 配置session的建立方式:線程方式建立session對象 -->        <property name="hibernate.current_session_context_class">thread</property>                <!--****************** 【串連池配置】****************** -->        <!-- 配置串連驅動管理類 -->        <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>        <!-- 配置串連池參數資訊 -->        <property name="hibernate.c3p0.min_size">2</property>        <property name="hibernate.c3p0.max_size">4</property>        <property name="hibernate.c3p0.timeout">5000</property>        <property name="hibernate.c3p0.max_statements">10</property>        <property name="hibernate.c3p0.idle_test_period">30000</property>        <property name="hibernate.c3p0.acquire_increment">2</property>                <!--****************** 【二級緩衝配置】****************** -->        <!-- a.  開啟二級緩衝 -->        <property name="hibernate.cache.use_second_level_cache">true</property>        <!-- b. 指定使用哪一個緩衝架構(預設提供的) -->        <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>        <!-- 開啟查詢快取 -->        <property name="hibernate.cache.use_query_cache">true</property>        <!-- c. 指定哪一些類,需要加入二級緩衝 -->        <class-cache usage="read-write" class="包名.類名"/>        <class-cache usage="read-only" class="包名.類名"/>        <!-- 集合緩衝[集合緩衝的元素對象,也加加入二級緩衝] -->        <collection-cache usage="read-write" collection="包名.類名.類裡的屬性"/>                                <!-- 3. 載入所有映射         <mapping resource="cn/itcast/a_hello/Employee.hbm.xml"/>        -->    </session-factory></hibernate-configuration>

 

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.