[英]@OneToOne or @ManyToOne on 'univ_orientation.dz.Entity.cursusGlobale.Student_idStudent' references an unknown entity: int
I'm working in a web app with Hibernate 5 and SpringMVC, when I worked just with simple tables (without relationships between any tables) everything work okay, update, save, delete..., but if I try to add some relationships between tables, and when I mapped, I got this error : 我正在使用Hibernate 5和SpringMVC的Web应用程序,当我只使用简单的表(没有任何表之间的关系)时,一切正常,更新,保存,删除......,但如果我尝试添加一些关系表,当我映射时,我收到此错误:
@OneToOne or @ManyToOne on 'univ_orientation.dz.Entity.cursusGlobale.Student_idStudent' references an unknown entity: int
I had searched to solve this issue, I found out that its a configuration problem, Hibernate doesn't recognize class cursusGlobale
as an entity. 我曾经搜索过要解决这个问题,我发现它是一个配置问题,Hibernate不会将类
cursusGlobale
识别为实体。
My question is why Hibernate doesn't recognize class cursusGlobale
as an entity when I work with relationships, but it does if I work just with simple tables without relationships between tables? 我的问题是为什么Hibernate在处理关系时不会将类
cursusGlobale
识别为实体,但如果我只处理表之间没有关系的简单表,它会怎么做?
package univ_orientation.dz.Entity;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name="cursusGlobale")
public class cursusGlobale {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="idcursusGlobale")
private int idcursusGlobale;
@Column(name="nbrRedoubler")
private int nbrRedoubler;
@Column(name="nbrDette")
private int nbrDette;
@Column(name="idStudent")
private int idStudent;
@OneToOne( cascade= CascadeType.ALL)
@JoinColumn(name="Student_idStudent")
private int Student_idStudent;
public cursusGlobale() {
}
public cursusGlobale(int nbrRedoubler, int nbrDette, int
student_idStudent) {
super();
this.nbrRedoubler = nbrRedoubler;
this.nbrDette = nbrDette;
idStudent = student_idStudent;
}
public int getIdcursusGlobale() {
return idcursusGlobale;
}
public void setIdcursusGlobale(int idcursusGlobale) {
this.idcursusGlobale = idcursusGlobale;
}
public int getNbrRedoubler() {
return nbrRedoubler;
}
public void setNbrRedoubler(int nbrRedoubler) {
this.nbrRedoubler = nbrRedoubler;
}
public int getNbrDette() {
return nbrDette;
}
public void setNbrDette(int nbrDette) {
this.nbrDette = nbrDette;
}
public int getIdStudent() {
return idStudent;
}
public void setIdStudent(int idStudent) {
this.idStudent = idStudent;
}
}
You have not create a relationship. 你还没有建立关系。 You are using a java native type
int
instead of another class Student
. 您正在使用java本机类型
int
而不是另一个类Student
。
@OneToOne( cascade= CascadeType.ALL)
@JoinColumn(name="Student_idStudent")
private int Student_idStudent;
As the error message clearly says: @OneToOne or @ManyToOne on 'univ_orientation.dz.Entity.cursusGlobale.Student_idStudent' references an unknown entity: int
, Student_idStudent is defined as an int, not as an Entity. 正如错误消息清楚地说:
@OneToOne or @ManyToOne on 'univ_orientation.dz.Entity.cursusGlobale.Student_idStudent' references an unknown entity: int
, Student_idStudent被定义为int,而不是实体。 You will need something more along the lines of 你将需要更多的东西
@OneToOne( cascade= CascadeType.ALL)
@JoinColumn(name="Student_idStudent")
private Student student;
Even though it is a class it will be persisted as a Foreign Key
to the Student
table in the database. 即使它是一个类,它也将作为
Foreign Key
在数据库中的Student
表中。 This is part of the abstraction provided by JPA. 这是JPA提供的抽象的一部分。
Reference: JPA Hibernate One-to-One relationship 参考: JPA Hibernate One-to-One关系
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.