简体   繁体   English

'univ_orientation.dz.Entity.cursusGlobale.Student_idStudent'上的@OneToOne或@ManyToOne引用了一个未知实体:int

[英]@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: intStudent_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.

相关问题 @OneToOne 或 @ManyToOne 引用未知实体 - @OneToOne or @ManyToOne on references an unknown entity * 未知实体上的 @OneToOne 或 @ManyToOne - @OneToOne or @ManyToOne on * an unknown entity JPA OneToMany ManyToOne @OneToOne或@ManyToOne在引用未知实体时: - JPA OneToMany ManyToOne @OneToOne or @ManyToOne on references an unknown entity: org.hibernate.AnnotationException: @OneToOne 或 @ManyToOne<entity> 引用一个未知实体 - org.hibernate.AnnotationException: @OneToOne or @ManyToOne on <entity> references an unknown entity Spring 引导错误:@OneToOne 或 @ManyToOne 引用未知实体 - Spring Boot Error: @OneToOne or @ManyToOne references an unknown entity xxx 上的 @OneToOne 或 @ManyToOne 引用了一个未知实体:java.util.Set - @OneToOne or @ManyToOne on xxx references an unknown entity: java.util.Set Hibernate @ManyToOne 引用了一个未知实体 - Hibernate @ManyToOne references an unknown entity Java Hibernate org.hibernate.AnnotationException:@OneToOne或@ManyToOne <class> 引用未知实体: <class> - Java Hibernate org.hibernate.AnnotationException: @OneToOne or @ManyToOne on <class> references an unknown entity: <class> AnnotationException:org.am.Car.engine上的@OneToOne或@ManyToOne引用了未知实体:org.am.Engine - AnnotationException: @OneToOne or @ManyToOne on org.am.Car.engine references an unknown entity: org.am.Engine 由以下原因引起:org.hibernate.AnnotationException:XX上的@OneToOne或@ManyToOne引用了未知实体:YY - Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on XX references an unknown entity: YY
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM