Mysql Spring数据JPA无法在数据库中创建表
我正在为库存管理创建Restful API,我已经创建了实体并填充了application.properties,但当我运行应用程序创建数据库和表时,只创建了数据库,没有显示任何错误 application.properties:Mysql Spring数据JPA无法在数据库中创建表,mysql,spring-boot,hibernate,spring-data-jpa,Mysql,Spring Boot,Hibernate,Spring Data Jpa,我正在为库存管理创建Restful API,我已经创建了实体并填充了application.properties,但当我运行应用程序创建数据库和表时,只创建了数据库,没有显示任何错误 application.properties: server.port=8097 spring.datasource.url=jdbc:mysql://localhost:3306/exercice_db?serverTimezone=UTC&createDatabaseIfNotExist=true sp
server.port=8097
spring.datasource.url=jdbc:mysql://localhost:3306/exercice_db?serverTimezone=UTC&createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=
spring.jpa.generate-ddl=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=create
Application.java:
package org.sid;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProjectAppServerApplication {
public static void main(String[] args) {
SpringApplication.run(ProjectAppServerApplication.class, args);
}
}
Produit.java:
//imports
@Entity
@Table(name = "produit")
public class Produit {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long idProduit;
@Size(min=3, max=1000)
public String Desprod;
@Size(min=3, max=1000)
public String Catprod;
@OneToMany(mappedBy="produit", cascade=CascadeType.ALL)
Set<Acheter> acheter = new HashSet();
public Produit() {
super();
// TODO Auto-generated constructor stub
}
public Produit(String desprod, String catprod) {
super();
this.Desprod = desprod;
this.Catprod = catprod;
}
//Getters and Setters
}
有什么问题吗?尝试使用CompositeKey:
AcheterKey.java
@Embeddable
public class AcheterKey implements Serializable {
@Column(name = "idProduit")
Long produitId;
@Column(name = "idFrs")
Long frsId;
}
Acheter.java
@Entity
@Table(name = "acheter")
public class Acheter {
@EmbeddedId
AcheterKey id;
@ManyToOne
@MapsId("produitId")
@JoinColumn(name ="idProduit")
Produit produit;
@ManyToOne
@MapsId("frsId")
@JoinColumn(name ="idFrs")
Fournisseur fournisseur;
public String prixAchat;
//Constructor, Gettes and Setters
}
尝试在属性中定义方言。spring.jpa.database platform=org.hibernate.dialogue.mysql5innodbdialogue我已经在使用该集合“spring.jpa.show sql=true”来查看生成的sql命令。尝试向表“acheter”添加一个主键(id)你确定这是jpa要做的工作吗?我认为应该利用flyway/liquibase来创建表格
@Embeddable
public class AcheterKey implements Serializable {
@Column(name = "idProduit")
Long produitId;
@Column(name = "idFrs")
Long frsId;
}
@Entity
@Table(name = "acheter")
public class Acheter {
@EmbeddedId
AcheterKey id;
@ManyToOne
@MapsId("produitId")
@JoinColumn(name ="idProduit")
Produit produit;
@ManyToOne
@MapsId("frsId")
@JoinColumn(name ="idFrs")
Fournisseur fournisseur;
public String prixAchat;
//Constructor, Gettes and Setters
}