美文网首页
spring boot中配置spring data jpa

spring boot中配置spring data jpa

作者: 荀彧真人 | 来源:发表于2017-08-02 14:01 被阅读0次

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:启动时不做任何操作

相关文章

网友评论

      本文标题:spring boot中配置spring data jpa

      本文链接:https://www.haomeiwen.com/subject/lfnelxtx.html