1. 程式人生 > >Hibernate配置檔案之主配置檔案

Hibernate配置檔案之主配置檔案

Hibernate配置檔案,主配置檔案。

命名: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>
		<!-- 資料庫連線配置 -->
		<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>
		<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
		
		<property name="hibernate.show_sql">true</property>
		
		<!-- 載入所有對映 -->
		<mapping resource="cn/itcast/a_hello/Employee.hbm.xml"/>
	</session-factory>
</hibernate-configuration>

## MySQL

#hibernate.dialectorg.hibernate.dialect.MySQLDialect

#hibernate.dialectorg.hibernate.dialect.MySQLInnoDBDialect

#hibernate.dialectorg.hibernate.dialect.MySQLMyISAMDialect

#hibernate.connection.driver_classcom.mysql.jdbc.Driver

#hibernate.connection.urljdbc:mysql:///test

#hibernate.connection.username gavin

#hibernate.connection.password


Hibernate.properties

#hibernate.hbm2ddl.auto create-drop 每次在建立sessionFactory時候執行建立表;當呼叫sesisonFactory的close方法的時候,刪除表!

#hibernate.hbm2ddl.auto create   每次都重新建表; 如果表已經存在就先刪除再建立

#hibernate.hbm2ddl.auto update  如果表不存在就建立; 表存在就不建立;

#hibernate.hbm2ddl.auto validate  (生成環境時候) 執行驗證: 當對映檔案的內容與資料庫表結構不一樣的時候就報錯!