【发布时间】:2017-01-29 20:45:15
【问题描述】:
这可能是一个重复的问题,也可能是一个非常基本的问题,但我需要一些帮助...
所以我正在使用 Spring Boot 构建一个应用程序,我有学生和班级,许多学生可以在一个班级中,所以这是多对一的。这就是我所做的:
@Entity
@Data
public class Eleve implements Serializable{
@Id
@GeneratedValue
private int idEt;
private String nomEt;
private String prenomEt;
@Column(length=1)
private String sexe;
private Date dobEt;
private String adresseEt;
private String telEt;
private String parentName;
private Date dateInscription;
private Date dateSortie;
@ManyToOne
private Classe classe;
}
这是有效的,我在 eleve 表中看到了classe_id_cl,但它不是foreign_key!此列可以接受任何值。
更新 顺便说一句,这是我的 application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/spring-boot-edss
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.session.store-type=none
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
我需要使用flywayDB之类的东西并强制它成为foreign_key吗?
【问题讨论】: