我正在尝试使用spring jpa在数据库上的两个不同表之间建立关系。但是,每次我尝试执行@OnetoMany或@ManytoOne时,都会收到标题中提到的错误。
学生:
package EIC.com.example.Backend.Entity;
import org.hibernate.annotations.Cascade;
import javax.persistence.*;
@Entity
@Table(name = "etudiant")
public class Student {
@Id
@Column(name="Apogee")
private int id;
@Column(name="Prenom")
private String first_name;
@Column(name="Nom")
private String last_name;
@Column(name="Classement")
private int rank;
@Column(name="Filiere")
private String speciality;
@ManyToOne
@Column(name = "Offre")
private Offer school;
/* GETTERS SETTERS CONSTRUCTORS */
}
优惠:
package EIC.com.example.Backend.Entity;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Entity
public class Offer {
@Id
@Column(name = "ID_OFFRE")
private int id;
@Column(name = "Type")
private int type; // 0 for DD 1 for MOBILITY
@Column(name = "Etablissement")
private String school;
@Column(name = "Filiere_Concerne")
private String target;
@Column(name = "Nb_place")
private int seats;
@Column(name = "Delai")
private Date limit;
@OneToMany
@JoinColumn(name = "Offre")
private List<Student> students=new ArrayList<>();
/* GETTERS SETTERS CONSTRUCTORS */
}
依赖项:
http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0 org.springframework.boot 弹簧启动启动器父母 2.1.2发布 EIC.com.example 后端 0.0.1-快照 后端 带有Spring Boot和Angular的EIC项目
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
答案 0 :(得分:0)
我认为您看到的错误与您发布的Bean的配置无关。引导程序正在为您创建此entityManager,但无法成功。
检查this post-这可能是关键。
答案 1 :(得分:0)
U不能一次拥有@Column
和@ManyToOne
使用@JoinColumn
代替@Column
。
您的学生班级应该像这样:
@Entity
@Table(name = "etudiant")
public class Student {
@Id
@Column(name="Apogee")
private int id;
@Column(name="Prenom")
private String first_name;
@Column(name="Nom")
private String last_name;
@Column(name="Classement")
private int rank;
@Column(name="Filiere")
private String speciality;
@ManyToOne
@JoinColumn(name = "Offre")
private Offer school;
/* GETTERS SETTERS CONSTRUCTORS */
}