hibernate配置檔案,一般命名為hibernate.cfg.xml
阿新 • • 發佈:2019-02-01
<?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>
<!-- 1 資料庫部分配置 必須-->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///hibernate_day01</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<!-- 配置c3p0連線池 -->
<!-- <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> -->
<!-- 2 hibernate基本配置 可選 -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!--
建立資料庫表,需要配置實現
create-drop: 如果資料庫存在相同的表,把表刪除再建立
create:如果資料庫存在相同的表,再建立相同欄位的表
update:如果資料庫存在相同的表,把表更新,如果沒有表,建立表
validate:如果資料庫存在相同的表,把表更新,如果沒有表,建立表;多個校驗功能:資料庫表字段必須和實體類屬性完全一樣
-->
<property name="hibernate.hbm2ddl.auto">update</property>
<!--
配置資料庫方言
mysql做分頁使用limit關鍵字,limit關鍵字只能使用在mysql裡面
oracle使用rownum,只能使用oracle裡面
-->
<!-- 3 引入對映檔案 必須-->
<mapping resource="cn/itcast/entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<!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>
<!-- 1 資料庫部分配置 必須-->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///hibernate_day01</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<!-- 配置c3p0連線池 -->
<!-- <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> -->
<!-- 2 hibernate基本配置 可選 -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!--
建立資料庫表,需要配置實現
create-drop: 如果資料庫存在相同的表,把表刪除再建立
create:如果資料庫存在相同的表,再建立相同欄位的表
update:如果資料庫存在相同的表,把表更新,如果沒有表,建立表
validate:如果資料庫存在相同的表,把表更新,如果沒有表,建立表;多個校驗功能:資料庫表字段必須和實體類屬性完全一樣
-->
<property name="hibernate.hbm2ddl.auto">update</property>
<!--
配置資料庫方言
mysql做分頁使用limit關鍵字,limit關鍵字只能使用在mysql裡面
oracle使用rownum,只能使用oracle裡面
-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 與執行緒繫結 -->
<property name="hibernate.current_session_context_class">thread</property>
<!-- 3 引入對映檔案 必須-->
<mapping resource="cn/itcast/entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>