spring.jpa.hibernate.ddl-auto = update mariadb无法自动创建数据库索引或外键或列

时间:2016-12-20 06:17:49

标签: java jpa gradle spring-boot create-table

1.spring boot

spring-boot-gradle-plugin:1.4.2.RELEASE

2.gradle

 dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '1.1.8'
}

3.application.properties

spring.jpa.hibernate.ddl-auto=update

4.Entity

    @Entity public class Users { @Id
    private int id;

    @Column(nullable = false,unique = true)
    private int userId;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }
}

Hibernate无法自动创建数据库索引或外键或约束或添加列

但是,当

spring-boot-gradle-plugin:1.2.4.RELEASE
一切都很正常

如何解决

1 个答案:

答案 0 :(得分:0)

发现问题,mariadb版本太低了

compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '1.1.8'

更改为

compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '1.5.6'

一切都好!