Javed
Javed

Reputation: 81

Spring boot and issue with ddl-auto

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

Upvotes: 2

Views: 1966

Answers (2)

Jason
Jason

Reputation: 7646

When ddl-auto = create, it wipes out the tables and re-creates them, so drop-create is the expected behavior and I'd expect you to lose your data. The only surprising thing is that it leaves table A alone. In my case, my integration tests that use ddl-auto=create don't access the table that still has data in it after the run. So I think it doesn't recreate tables that aren't accessed.

Upvotes: 1

harelguy
harelguy

Reputation: 31

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...)

Upvotes: 0

Related Questions