【发布时间】: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 工作台中创建的表。我试了很多次都没有成功。如果您找到解决方案,请告诉我。干杯!
【问题讨论】:
-
@samabcde 不是真的。我拥有的属性文件配置适用于所有其他项目,除了这个项目。
标签: java hibernate api spring-data-jpa mysql-workbench