標籤:
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的常用配置