您的位置:首页 > 编程语言 > Java开发

SpringData 自动创建表设置配置

2017-08-23 09:31 113 查看

可以通过hibernate.ddl.auto节点的配置,这个配置有两种方式去配置,我使用的是通过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
spring.jackson.serialization.indent_output=false

hibernate.ddl-auto节点的值有几个create、create-drop、update、validate、none

create:每次加载hibernate会自动创建表,以后启动会覆盖之前的表,所以这个值基本不用,严重会导致的数据的丢失。

create-drop
: 每次加载hibernate时根据model类生成表,但是sessionFactory一关闭,表就自动删除,下一次启动会重新创建。

update:
加载hibernate时根据实体类model创建数据库表,这是表名的依据是@Entity注解的值或者@Table注解的值,sessionFactory关闭表不会删除,且下一次启动会根据实体                   model更新结构或者有新的实体类会创建新的表。
validate:启动时验证表的结构,不会创建表
none:启动时不做任何操作
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐