Search code examples
spring-bootjpamariadbentitydialect

Spring boot/JPA connection to MariaDB cant create the entities


Hi i am just starting with spring and JPA. And all i want to start with is to connect to a remote db and create the entities that i have on my spring app.

I have a Maria DB server 5.7.24 in a VPS.

I have created a package named domain at /JpaTest/src/main/java/domain . And inside i have an object - Entity like this.

package domain;
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.AUTO)
    private Long id;
    private String username;
    private String password;
    private String name;    


    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

And my application.properties are like this...

spring.datasource.url=jdbc:mysql://URL:Port/dbName
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=admin_customer
spring.datasource.password=*********



spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

Like this, the program runs as a Spring boot app. But it creates no table. I have tried using spring.jpa.hibernate.ddl-auto=update , to change the Dialect to other versions, even go with org.hibernate.dialect.MariaDBDialect , or org.mariadb.jdbc.Driver and more.

But it just cant work. When i use any dialect or driver other than MySQL, the program cant run because it cant find them. When i use the settings above it executes but it does nothing.


Solution

  • You should add @Column(name = "name") before column and check your application config class have: @EntityScan("some.known.persistence")