Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Spring数据JPA无法在数据库中创建表_Mysql_Spring Boot_Hibernate_Spring Data Jpa - Fatal编程技术网

Mysql Spring数据JPA无法在数据库中创建表

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

我正在为库存管理创建Restful API,我已经创建了实体并填充了application.properties,但当我运行应用程序创建数据库和表时,只创建了数据库,没有显示任何错误

application.properties:

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
}