hql手动创建表
2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
---------------------------------手動用代碼進(jìn)行數(shù)據(jù)庫創(chuàng)建------------------------------
Configuration con=new Configuration();
con.configuration();
//創(chuàng)建工具類對象
SchemaExport export=new SchemaExport(con);
//建表
//第一個參數(shù) 控制臺打印建表語句
//第二個參數(shù) 執(zhí)行語句
export.create(true,true);
----------------------------------hibernate.cfg.xml方式創(chuàng)建數(shù)據(jù)庫表--------------------------------
服務(wù)啟動的時候就會創(chuàng)建
<property name="hibernate.hbm2ddl.auto">create-drop</property>每次在創(chuàng)建sessionFactory時候執(zhí)行創(chuàng)建表;當(dāng)調(diào)用sesisonFactory的close方法的時候,刪除表!
<property name="hibernate.hbm2ddl.auto">create</property>每次都重新建表,如果表已經(jīng)存在就先刪除再創(chuàng)建
<property name="hibernate.hbm2ddl.auto">update</property>??如果表不存在就創(chuàng)建; 表存在就不創(chuàng)建;
<property name="hibernate.hbm2ddl.auto">validate</property>??(生成環(huán)境時候) 執(zhí)行驗證: 當(dāng)映射文件的內(nèi)容與數(shù)據(jù)庫表結(jié)構(gòu)不一樣的時候就報錯!
轉(zhuǎn)載于:https://my.oschina.net/chenliyong/blog/668494
總結(jié)
- 上一篇: 阴阳师酒吞童子御魂怎么搭配 酒吞童子御魂
- 下一篇: Unit testing Cmocker