1. 程式人生 > 實用技巧 >hibernate的核心配置

hibernate的核心配置

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE hibernate-configuration PUBLIC
 3     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 4     "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
 5 <hibernate-configuration>
 6     <session-factory>
 7         <!-- 基礎配置
--> 8 <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property> 9 <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/資料庫名</property> 10 <property name="hibernate.connection.username">root</property>
11 <property name="hibernate.connection.password">123456</property> 12 13 <!-- 可選配置 --> 14 <!-- 列印sql語句 --> 15 <property name="hibernate.show_sql">true</property> 16 <!-- 格式化sql --> 17 <property
name="hibernate.format_sql">true</property> 18 <!-- 自動建立表 19 1.none :不使用自動建表 20 2.create :若有表,刪除重新建立;若沒有,建立表 21 3.create-drop :按create建立表,執行完操作後,刪除表 22 4.update :若有表,則使用;若無表,則建立(課更新表結構) 23 5.validate :若無表,則不建立新表,僅使用以有表 24 --> 25 <property name="hibernate.hbm2ddl.auto">create</property> 26 <!-- 設定資料庫隔離級別 --> 27 <property name="hibernate.connection.isolation">4</property> 28 <!-- 配置當前執行緒繫結的session --> 29 <property name="hibernate.current_session_context_class">thread</property> 30 31 <!-- 新增對映 --> 32 <mapping resource="/hibernate/src/cn/edu/ahtcm/yrxc/text/aaa.hbm.xml"/> 33 </session-factory> 34 </hibernate-configuration>