Hibernate基礎配置——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>
       <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
       <property name="hibernate.connection.username">root</property>
       <property name="hibernate.connection.password">123</property>
       <property name="hibernate.onnection.driver_class">com.mysql.jdbc.Driver</property>
       <property name="connection.url">
		<![CDATA[
		jdbc:mysql://localhost:3306/imooc?useUnicode=true&characterEncoding=utf8
		]]>
       </property>

	<property name="show_sql">true</property>
		<!--sql代碼格式化-->
	<property name="format_sql">true</property>  
	<property name="hbm2ddl.auto">update</property>
	<!-- 使用getCurrentSession需要的配置,thread是本地事物(jsbc事物), 全局事物是jta -->
	<property name="hibernate.current_session_context_class">thread</property>
	<!--  指定映射文件的路徑  -->
<mapping class="com.imooc.entity.Grade" resource="com/imooc/entity/Grade.hbm.xml"/>
<mapping class="com.imooc.entity.Student" resource="com/imooc/entity/Student.hbm.xml"/>
	</session-factory>

</hibernate-configuration>

<prop key="hibernate.hbm2ddl.auto">value</prop>

其中value的值如下:

create:表示啓動的時候先drop,再create

create-drop: 也表示創建,只不過再系統關閉前執行一下drop

update: 這個操作啓動的時候會去檢查schema是否一致,如果不一致會做scheme更新

validate: 啓動時驗證現有schema與你配置的hibernate是否一致,如果不一致就拋出異常,並不做更新

如果沒做配置,那麼就需要手動創建.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章