![](/img/trans.png)
[英]Spring Boot HIbernate Issue: Error executing DDL via JDBC Statement with ddl-auto=create-drop
[英]Spring boot and issue with ddl-auto
目前正在使用spring-boot來使用Spring MVC和JPA數據創建Web應用程序,但是遇到了spring.jpa.hibernate.ddl-auto屬性的問題:似乎在第一次運行表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-AUTO
當ddl-auto = create時,它將清除表並重新創建它們,因此drop-create是預期的行為,我希望您會丟失數據。 唯一令人驚訝的是,它只剩下表A。 就我而言,使用ddl-auto = create的集成測試在運行后不會訪問仍然有數據的表。 因此,我認為它不會重新創建未訪問的表。
也許您有外鍵約束? 我在使用MySQL表時遇到了這個問題,如果表是另一個表的外鍵,則不能對表進行截斷或刪除(即使這不會破壞任何“真實”記錄...)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.