简体   繁体   中英

Table is not getting Created in mysql schema from Spring boot JPA

I am creating one spring boot application and trying to make a connection with mysql database.

I have created a schema. and trying to add columns in table through spring boot jpa.

Even though my build is geeting passed I am not able to get sucess. I have tried all the possible way fromthe stackover flow but no luck.

Here is my application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?useSSL=false
spring.datasource.username=root
spring.datasource.password=root

spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto= update

And this my model class

package com.springboot.Model;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "employees")

public class Employee {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    
    @Column(name = "first_name")
    private String  fristName;
    
    @Column(name = "last_name")
    private String lastName;
    
    @Column(name = "email_id")
    private String emailId;
    
    public Employee() {
        
    }
    
    public Employee(String fristName, String lastName, String emailId) {
        super();
        this.fristName = fristName;
        this.lastName = lastName;
        this.emailId = emailId;
    }
    
    
    public long getId() {
        return id;
    }
    
    public void setId(long id) {
        this.id = id;
    }
    
    public String getFristName() {
        return fristName;
    }
    
    
    public void setFristName(String fristName) {
        this.fristName = fristName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmailId() {
        return emailId;
    }
    public void setEmailId(String emailId) {
        this.emailId = emailId;
    }
}

Build log: 构建日志

I have doubt on my db connection also. what is the way to debug or findout wheather the spring it is hitting the schema or not.

Can anybody help me here. This is my first Spring java application.

Need to add createDatabaseIfNotExist=true parameter in datasource URL as shown in below example:

spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?createDatabaseIfNotExist=true&useSSL=false

Are you sure your Entity is under the base package or under the sub-package of base-package? If not, then you need to add it to Scan in the main application file:

@EntityScan(basePackages = {"com.springboot.Model"}) 

Try below properties:

spring.jpa.generate-ddl=true <br>
spring.jpa.hibernate.ddl-auto=create

Try adding spring.jpa.defer-datasource-initialization= true in properties file.

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