spring boot中配置spring data jpa

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节点的值有几个create、create-drop、update、validate、none

  • create:每次加载hibernate会自动创建表,以后启动会覆盖之前的表,所以这个值基本不用,严重会导致的数据的丢失。
  • create-drop : 每次加载hibernate时根据model类生成表,但是sessionFactory一关闭,表就自动删除,下一次启动会重新创建。
  • update:加载hibernate时根据实体类model创建数据库表,这是表名的依据是@Entity注解的值或者@Table注解的值,sessionFactory关闭表不会删除,且下一次启动会根据实体model更新结构或者有新的实体类会创建新的表。
  • validate:启动时验证表的结构,不会创建表
  • none:启动时不做任何操作
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容