当前位置: 首页 > 知识库问答 >
问题:

使用ddl-auto启动和发布Spring

钦侯林
2023-03-14

我目前正在使用spring-boot创建一个使用Spring MVC和JPA数据的web应用程序,但是我遇到了一个问题:属性Spring.JPA.hibernate.ddl-auto:create似乎在第一次运行时正确创建了表a、B、C。然后,我填充所有3个表,当我关闭应用程序并重新运行它时,只有表A仍然包含填充的数据。

B表和C表被完全抹掉了,这有点奇怪。

我的pom.xml中有以下内容作为依赖项

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>0.5.0.M6</version>
</parent>


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>
    </dependencies>

</dependencyManagement>

<dependencies>
    <!-- Web Dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>

    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring3</artifactId>
    </dependency>
    <dependency>
        <groupId>nz.net.ultraq.thymeleaf</groupId>
        <artifactId>thymeleaf-layout-dialect</artifactId>
    </dependency>


    <!-- Persistence -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!-- Test -->
    <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <classifier>tests</classifier>
    </dependency> -->

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>

    </dependency>

    <!-- Database -->
<!--<dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> 
        <scope>runtime</scope> </dependency> -->

         <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.26</version>
    </dependency>

    <!-- Validation Dependencies -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>


</dependencies>

spring.jpa.hibernate.ddl-自动

共有1个答案

丁沛
2023-03-14

当ddl-auto=create时,它会清除表并重新创建它们,因此drop-create是预期的行为,我希望您会丢失数据。唯一让人吃惊的是,它把A表单独留下了。在我的例子中,使用ddl-auto=create的集成测试不访问运行后仍有数据的表。所以我认为它不会重新创建未访问的表。

 类似资料:
  • 我正在创建一个基于spring JPA注释的安全服务。在的数据源配置中,我有以下配置

  • 我正在尝试用MySQL数据库和Hibernate作为JPA创建一个简单的spring boot Web应用程序。我使用的是spring boot 2.0.3版本。 我希望这些表是自动创建的,并自动填充初始数据。为了做到这一点,我做了以下几件事:1。用@Entity 2标记POJO。application.properties 3中的spring.jpa.hibernate.ddl-auto=upd

  • 当SpringWebServiceStarter与2.1一起使用时,我无法构建SpringBoot应用程序。13.Spring护套的释放版本。这是因为SpringWS-core:jar:3.0。8.释放。 构建应用程序时出现异常:它出现在默认测试用例执行期间。 警告: 组织的POM。springframework。ws:springws-core:jar:3.0。8.版本无效,可传递依赖项(如果有

  • 我正在使用带有的spring boot,但是当应用程序重新启动时,所有表都会删除并重新创建。有什么方法可以避免重新创建已经存在的表吗?

  • 如果spring-boot-starter-parent是2.0.0,则无法从STS启动Spring Boot应用程序。如果将其设置为1.5.0,则为release或更高版本。release可以工作,但我使用的是可选的,从Spring2.0开始就支持可选的。

  • 我正在尝试在应用程序启动时使用spring cloud stream向rabbitmq发送消息。使用下面的示例代码。 启用绑定的SpringBoot应用程序 应在启动时发送消息的应用程序运行程序 除非我取消注释上面注释掉的代码,否则上面的代码会产生下面的异常。 我正在使用Spring Boot 2.0.2和Sprig Cloud Stream 2.0.0,如下面的pom所示 根据这个公认的答案ht