hibernate設定檔

來源:互聯網
上載者:User

標籤:

1、配置的方式:
  •     hibernate.properties
  •     hibernate.cfg.xml
  •     編碼方式建立Configuration對象
        hibernate.properties     採用這種方式配置時:檔案配置時可以參考hibernate發布包中project\etc下hibernate.properties檔案,但該檔案沒有添加持久化類的方式,所以必須調用Configuration對象的addAnnotatedClass()或addPackage()添加持久化類。  
 Configuration cfg = new Configuration().addAnnotatedClass(Item.class)
.addAnnotatedClass(Bid.class);

   實際開發中一般不用,因為當類很多時,工作量會很大。

     hibernate.cfg.xml    在設定檔裡加了持久化類           Configuration cfg = new Configuration().configure();       編程方式加(很少用)            // 執行個體化Configuration,不載入任何設定檔        Configuration conf = new Configuration()            // 通過addAnnotatedClass()方法添加持久化類            .addAnnotatedClass(org.crazyit.app.domain.News.class)            // 通過setProperty設定Hibernate的串連屬性。            .setProperty("hibernate.connection.driver_class"                , "com.mysql.jdbc.Driver")            .setProperty("hibernate.hbm2ddl.auto" , "update"); 2、常用配置屬性     
  <!-- 指定串連資料庫所用的驅動 -->        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>        <!-- 指定串連資料庫的url,其中hibernate是本應用串連的資料庫名 -->        <property name="connection.url">jdbc:mysql://localhost/hibernate</property>        <!-- 指定串連資料庫的使用者名稱 -->        <property name="connection.username">root</property>        <!-- 指定串連資料庫的密碼 -->        <property name="connection.password">32147</property>        <!-- 指定串連池裡最大串連數 -->        <property name="hibernate.c3p0.max_size">20</property>        <!-- 指定串連池裡最小串連數 -->        <property name="hibernate.c3p0.min_size">1</property>        <!-- 指定串連池裡串連的逾時時間長度 -->        <property name="hibernate.c3p0.timeout">5000</property>        <!-- 指定串連池裡最大緩衝多少個Statement對象 -->        <property name="hibernate.c3p0.max_statements">100</property>        <property name="hibernate.c3p0.idle_test_period">3000</property>        <property name="hibernate.c3p0.acquire_increment">2</property>        <property name="hibernate.c3p0.validate">true</property>        <!-- 指定資料庫方言 -->        <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>        <!-- 根據需要自動建立資料表 -->        <property name="hbm2ddl.auto">update</property><!--①-->        <!-- 顯示Hibernate持久化操作所產生的SQL -->        <property name="show_sql">true</property>        <!-- 將SQL指令碼進行格式化後再輸出 -->        <property name="hibernate.format_sql">true</property>        <!-- 羅列所有持久化類的類名 -->        <mapping class="org.crazyit.app.domain.News"/>        
View Code

 

 

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.