Shubbi
Shubbi

Reputation: 65

Entity class not creating a table in mySql database using jpa

While I can create tables in other projects but this project is not creating table from the entity class.I have following entity class in spring boot jpa using eclipse:

package com.abc.allcoaches.entity;

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


@Entity
@Table(name = "Coaches_TBL")

public class Coaches {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;
    private String t;
    private String c;
    
    
    
    public Coaches() {
        
    }
    
    public Coaches(int id, String team, String coach ) {
        
        super();
        this.id = id;
        this.t = team;
        this.c = coach;
        
    
    }

    public int getId() {
        return id;
    }

    public void setID(int id) {
        this.id = id;
    }

    public String getT() {
        return t;
    }

    public void setT(String t) {
        this.t = t;
    }

    public String getC() {
        return c;
    }

    public void setC(String c) {
        this.c = c;
    }

    
    
}


The repository class is as below:

package com.abc.allcoaches.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.abc.allcoaches.entity.Coaches;


public interface CoachesRepository extends JpaRepository<Coaches, Integer> {

    Coaches findByTeam(String team);
    
}

Here is the property file:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/football2020db
spring.datasource.username = root
spring.datasource.password = password
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

But after running the project without any error, I dont see table created in mySql work bench. I tried multiple times without any success. Please let me know if you find a solution. Cheers!

Upvotes: 1

Views: 1827

Answers (1)

Shubbi
Shubbi

Reputation: 65

I found the problem which was causing the table not being created. My application class (with main(String [] args) method) was in a different package. I refactored the packages and the problem was resolved.

Upvotes: 2

Related Questions