【问题标题】:Entity class not creating a table in mySql database using jpa实体类未使用 jpa 在 mySql 数据库中创建表
【发布时间】:2021-02-05 02:03:05
【问题描述】:

虽然我可以在其他项目中创建表,但该项目不是从实体类创建表。我在 spring boot jpa 中使用 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;
    }

    
    
}


仓库类如下:

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);
    
}

这是属性文件:

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

但是在运行项目没有任何错误后,我没有看到在 mySql 工作台中创建的表。我试了很多次都没有成功。如果您找到解决方案,请告诉我。干杯!

【问题讨论】:

标签: java hibernate api spring-data-jpa mysql-workbench


【解决方案1】:

我发现了导致表未创建的问题。我的应用程序类(使用 main(String [] args) 方法)位于不同的包中。我重构了包,问题解决了。

【讨论】:

    猜你喜欢
    • 2016-03-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多