简体   繁体   中英

Tables not created, Using Entities from maven jar dependency in multiple applications in Spring Boot

Having Two Projects

  1. my-app

  2. my-entities

I have my entities in my-entities and i uploading this repository to bitbucket fro hosting then using same repository in my "my-app" project which is a spring boot application and containing database configs like username, dbname, password and i am using spring data jpa with

spring.jpa.hibernate.ddl-auto=update

Sample Entity class present in my-enties

@Entity
public class OrganisationDetails {

    @Id
    @GeneratedValue
    private Long id;


    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "OrganisationDetails{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}

But tables are not created automatically.

spring.jpa.hibernate.ddl-auto=update - is used to update the current schema

spring.jpa.hibernate.ddl-auto=create - is used to create new schema

Normally in development phases the combination - create-drop is used

spring.jpa.hibernate.ddl-auto=create-drop

You can read more on how to initialize database with spring-boot and JPA here .

Another vital thing is to specify your SQL dialect. For example for MySql5

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

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