简体   繁体   中英

spring.jpa.hibernate.ddl-auto=update mariadb can not auto create Database indexes or Foreign key or column

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 can not auto create Database indexes or Foreign key or constraint or add column

but,when

spring-boot-gradle-plugin:1.2.4.RELEASE

everything is normal

How to solve

Found the problem, mariadb version is too low

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

change to

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

everything is OK !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM