Issue
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;
}
}
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.
Solution
Are you sure your
Entity
is under the base package or the sub-package of base-package? If not , then you need to add it toScan
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
Answered By - Tarun