Hibernate -- hibernate.cfg.xml 核心設定檔

來源:互聯網
上載者:User

標籤:

<?xml version="1.0" encoding="UTF-8"?><!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>        <!-- property 元素用於配置Hibernate中的屬性            鍵:值           -->          <!-- hibernate.connection.driver_class : 串連資料庫的驅動  -->        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

<!-- hibernate.connection.username : 串連資料庫的使用者名稱 --> <property name="hibernate.connection.username">root</property>

<!-- hibernate.connection.password : 串連資料庫的密碼 --> <property name="hibernate.connection.password">123</property>

<!-- hibernate.connection.url : 串連資料庫的地址,路徑 --> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatedemo</property>

<!-------------------------------------------------------------------------------->

<!-- show_sql: 操作資料庫時,會 向控制台列印sql語句 --> <property name="show_sql">true</property>

<!-------------------------------------------------------------------------------->

<!-- format_sql: 列印sql語句前,會將sql語句先格式化 --> <property name="format_sql">true</property>

<!-------------------------------------------------------------------------------->

<!-- hbm2ddl.auto: 產生表結構的策略配置 update(最常用的取值): 如果當前資料庫中不存在表結構,那麼自動建立表結構. 如果存在表結構,並且表結構與實體一致,那麼不做修改 如果存在表結構,並且表結構與實體不一致,那麼會修改表結構.會保留原有列. create(很少):無論是否存在表結構.每次啟動Hibernate都會重新建立表結構.(資料會丟失) create-drop(極少): 無論是否存在表結構.每次啟動Hibernate都會重新建立表結構.每次Hibernate運行結束時,刪除表結構. validate(很少):不會自動建立表結構.也不會自動維護表結構.Hibernate只校正表結構. 如果表結構不一致將會拋出異常. --> <property name="hbm2ddl.auto">update</property>

<!-------------------------------------------------------------------------------->

<!-- 資料庫方言配置 org.hibernate.dialect.MySQLDialect (選擇最短的) --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<!-------------------------------------------------------------------------------->

<!-- hibernate.connection.autocommit: 事務自動認可 --> <property name="hibernate.connection.autocommit">true</property>

<!-------------------------------------------------------------------------------->

<!-- 將Session與線程綁定=> 只有配置了該配置,才能使用getCurrentSession --> <property name="hibernate.current_session_context_class">thread</property>

<!-------------------------------------------------------------------------------->

<!-- 引入ORM 對應檔 填寫src之後的路徑 --> <mapping resource="com/itheima/a_hello/User.hbm.xml"/> </session-factory></hibernate-configuration>

 

Hibernate -- hibernate.cfg.xml 核心設定檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.