Spring boot and issue with ddl-auto

By : Javed
Source: Stackoverflow.com
Question!

am currently using spring-boot to create a web app using Spring MVC and JPA data however am getting an issue with property spring.jpa.hibernate.ddl-auto: create as it appears that on the first run my tables A , B , C are created correctly. Then i populate all the 3 tables and when I close the application and re-run it only Table A still contains the populated data.

The tables B and C are wiped out completely which is a bit strange .

Any one know why this is the case?

I have the following within my pom.xml as dependencies

<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

By : Javed


Answers

Perhaps you have a foreign key contraint? I've had this problem using MySQL tables, the tables can't be TRUNCATEd or DROPed if the table is the foreign key of a different one (even if this doesn't break any "real" records...)

By : harelguy


This video can help you solving your question :)
By: admin