0

I'm unable to get spring boot to automatically load my database schema when I start it up.

Here is my application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/user_details?useSSL=true
spring.datasource.username=
spring.datasource.password=

I set the username and password already.

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

Here is my Application.java:

package com.ecommerce.omazon;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class OmazonApplication {

public static void main(String[] args) {
    SpringApplication.run(OmazonApplication.class, args);
}

}

This is my entity

package net.javaguides.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 = "Users")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column (name = "Username")
    private String Username;
    @Column (name = "Password")
    private String Password;
    @Column (name = "Email")
    private String Email;

public User() {

}
public User(String username, String password, String email) {
    Username = username;
    Password = password;
    Email = email;
}

public long getId() {
    return id;
}
public void setId(long id) {
    this.id = id;
}
public String getUsername() {
    return Username;
}
public void setUsername(String username) {
    Username = username;
}
public String getPassword() {
    return Password;
}
public void setPassword(String password) {
    Password = password;
}
public String getEmail() {
    return Email;
}
public void setEmail(String email) {
    Email = email;
}

}

Everything runs perfectly just when I try to refresh the schema in mysql workbench it is not creating a user file.

CopperCleric
  • 63
  • 2
  • 8
  • 1
    do you want to create a new table? https://stackoverflow.com/a/42147995/10006556 – Catur Ananta Jan 07 '22 at 02:34
  • not create but just update the table to mysql workbench.I dont want to create new table everytime and overwrite the old data – CopperCleric Jan 07 '22 at 02:46
  • 1
    Follow camel case conventions for fields in entity class – Alien Jan 07 '22 at 03:19
  • If you want to have total control over your database structure you may want to look into migration libraries such as `liquibase`. It allows you to write exact migrations in `xml` format in order of events and your model versions (e.g., create tables, then add or remove columns etc). It's less automatic but you can always be sure that you're not losing any data after removing a property from your entity as the column will only be deleted if you create a migration for that. Also in Spring, it could be configured to run automatically on application startup. – Pavel Polyakoff Jan 07 '22 at 14:45

0 Answers0