Hibernate--hibernate.cfg.xml配置
阿新 • • 發佈:2017-09-28
req pin 每次 valid mysq db_name local .hbm.xml for
數據庫連接<required>:
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/db_name
</property>
方言<required>:
<!-- 數據庫方言:指定連接的數據庫,要對應版本,否則無法建表 -->
<!-- hibernate5.0 MySQL5 -->
<!-- hibernate5.1 MySQL5InnoDBDialect -->
<property name="hibernate.dialect">
org.hibernate.dialect.MySQL5InnoDBDialect
</property>
SQL顯示方式:
<!-- 是否顯示SQL -->
<property name="hibernate.show_sql">true</property>
<!-- 是否格式化SQL -->
<property name="hibernate.format_sql">true</property>
<!-- 是否需要維護表結構 -->
<property name="hibernate.hbm2ddl.auto">update</property>
update:沒有就創建表,如果表改變了,則增量修改
在原表基礎上進行修改,原表數據不會刪除create:每次都會刪除舊表,創建新表
每次重新加載hibernate,重新創建數據庫表結構,可能會導致數據丟失
create-drop:先創建,測試完成後,刪除表
validate:校驗,不會自動生成表,每次啟動數據庫都會校驗數據庫中的表和實體是否一致,如果不一致,報錯
映射信息<required>:
<!-- mapping文件 -->
<mapping resource="com/roxy/hibernate/pojo/Customer.hbm.xml"/>
Hibernate--hibernate.cfg.xml配置