1. 程式人生 > >MYSQL驅動8.0.13和hibernate5.3.7配合的hibernate.cfg.xml

MYSQL驅動8.0.13和hibernate5.3.7配合的hibernate.cfg.xml

<?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>
	
		<!-- 
		#hibernate.dialect org.hibernate.dialect.MySQLDialect
		#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
		#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
		#hibernate.connection.driver_class com.mysql.jdbc.Driver
		#hibernate.connection.url jdbc:mysql:///test
		#hibernate.connection.username gavin
		#hibernate.connection.password
		 -->
		 <!-- 資料庫驅動 -->
		<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
		 <!-- 資料庫url -->
		<property name="hibernate.connection.url">jdbc:mysql:///hibernate-day01?useSSL=false&amp;serverTimezone=UTC</property>
		 <!-- 資料庫連線使用者名稱 -->
		<property name="hibernate.connection.username">root</property>
		 <!-- 資料庫連線密碼 -->
		<property name="hibernate.connection.password">root</property>
		<!-- 資料庫方言
			不同的資料庫中,sql語法略有區別. 指定方言可以讓hibernate框架在生成sql語句時.針對資料庫的方言生成.
			sql99標準: DDL 定義語言  庫表的增刪改查
					  DCL 控制語言  事務 許可權
					  DML 操縱語言  增刪改查
			注意: MYSQL在選擇方言時,請選擇最短的方言.
		 -->
		<property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
		<!-- 如果是獲取當前執行緒的session,沒有這個會報錯 -->
		<property name="current_session_context_class">thread</property>
		<!-- #hibernate.show_sql true 
			 #hibernate.format_sql true
		-->
		<!-- 將hibernate生成的sql語句列印到控制檯 -->
		<property name="hibernate.show_sql">true</property>
		<!-- 將hibernate生成的sql語句格式化(語法縮排) -->
		<property name="hibernate.format_sql">true</property>
		<!-- 
		## auto schema export  自動匯出表結構. 自動建表
		#hibernate.hbm2ddl.auto create		自動建表.每次框架執行都會建立新的表.以前表將會被覆蓋,表資料會丟失.(開發環境中測試使用)
		#hibernate.hbm2ddl.auto create-drop 自動建表.每次框架執行結束都會將所有表刪除.(開發環境中測試使用)
		#hibernate.hbm2ddl.auto update(推薦使用) 自動生成表.如果已經存在不會再生成.如果表有變動.自動更新表(不會刪除任何資料).
		#hibernate.hbm2ddl.auto validate	校驗.不自動生成表.每次啟動會校驗資料庫中表是否正確.校驗失敗.
		 -->
		<property name="hibernate.hbm2ddl.auto">update</property>
		<!-- 引入orm元資料
			路徑書寫: 填寫src下的路徑
		 -->
		<mapping resource="cn/itheima/domain/Customer.hbm.xml" />
		
	</session-factory>
</hibernate-configuration>