application.properties
#DataSource Config
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:6033/data_service?characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql= true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto節(jié)點(diǎn)的值有幾個(gè)create、create-drop简卧、update肥败、validate、none
- create:每次加載hibernate會(huì)自動(dòng)創(chuàng)建表更舞,以后啟動(dòng)會(huì)覆蓋之前的表畦幢,所以這個(gè)值基本不用,嚴(yán)重會(huì)導(dǎo)致的數(shù)據(jù)的丟失缆蝉。
- create-drop : 每次加載hibernate時(shí)根據(jù)model類生成表宇葱,但是sessionFactory一關(guān)閉瘦真,表就自動(dòng)刪除,下一次啟動(dòng)會(huì)重新創(chuàng)建黍瞧。
- update:加載hibernate時(shí)根據(jù)實(shí)體類model創(chuàng)建數(shù)據(jù)庫表诸尽,這是表名的依據(jù)是@Entity注解的值或者@Table注解的值,sessionFactory關(guān)閉表不會(huì)刪除印颤,且下一次啟動(dòng)會(huì)根據(jù)實(shí)體model更新結(jié)構(gòu)或者有新的實(shí)體類會(huì)創(chuàng)建新的表您机。
- validate:啟動(dòng)時(shí)驗(yàn)證表的結(jié)構(gòu),不會(huì)創(chuàng)建表
- none:啟動(dòng)時(shí)不做任何操作