【问题标题】:how to use spring.jpa.hibernate.ddl-auto如何使用 spring.jpa.hibernate.ddl-auto
【发布时间】:2018-04-11 01:33:20
【问题描述】:

我目前设置了 hibernate.ddl:

spring.jpa.hibernate.ddl-auto = create-drop 

我不会一次又一次地丢失我的数据... 我可以使用什么值而不是每次都删除和创建架构 有没有办法更新现有的?
我试图使用 update 代替 create-drop 但它引发了异常:

 [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.3.RELEASE:run (default-cli) on project fno-connector-core: 
An exception occurred while running. null: InvocationTargetException: 
Failed to execute SQL script statement #1 of URL [file:/D:/..../classes/data.sql]: 
insert into users (username, enabled, password, first_name, last_name, email) 
values ('admin', true, '************', 'Flexera', 'Admin', 'aurovindosahu@*****.com'); 
nested exception is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry 'admin' for key 'PRIMARY'

【问题讨论】:

    标签: mysql hibernate spring-boot


    【解决方案1】:

    spring.jpa.hibernate.ddl-auto 的可能值为e.g. none | validate | update | create | create-dropReference

    在你的用例中使用update

    【讨论】:

    • 首先我使用创建,然后如果我使用更新,那么它会抛出异常
    • 有什么异常?您可以先删除表,然后使用 update 重新运行新程序。
    猜你喜欢
    • 2022-08-11
    • 2021-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    相关资源
    最近更新 更多