org.hibernate.MappingException: Could not determine type for: com.qoobico.remindme.server.entity.Group, at table: student, for columns: [org.hibernate.mapping.Column(group)]
我阅读了有关此异常的所有帖子,但我无法解决该问题。看起来一切都很好,但我还是明白了:
Group.java
@Entity
@Table(name = "party")
public class Group {
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name="increment", strategy = "increment")
private int id_group;
@Column(name = "groupName", nullable = false)
private String groupName;
@Column(name = "tutorName", nullable = false)
private String tutorName;
@OneToMany(targetEntity = Student.class,
mappedBy = "group",
cascade = CascadeType.ALL,
fetch = FetchType.EAGER)
private List<Student> student;
public Group(){
}
public int getId_group() {
return id_group;
}
public void setId_group(int id_group) {
this.id_group = id_group;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getTutorName() {
return tutorName;
}
public void setTutorName(String tutorName) {
this.tutorName = tutorName;
}
public List<Student> getStudent() {
return student;
}
public void setStudent(List<Student> student) {
this.student = student;
}
}
Student.java
@Entity
@Table(name ="student")
public class Student {
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name="increment", strategy = "increment")
private int id_student;
@Column(name = "studentName", nullable = false)
private String studentName;
@Column(name = "formOfAducation")
private String formOfAducation;
@Column(name = "group")
private Group group;
@Column(name = "studentCourse")
private String studentCourse;
@Column(name = "studentSpecializatio")
private String studentSpecializatio;
@Column(name = "studentBookName")
private String studentBookName;
@Column(name = "studentGender")
private String studentGender;
public Student(){
}
public int getId_student() {
return id_student;
}
public void setId_student(int id_student) {
this.id_student = id_student;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getFormOfAducation() {
return formOfAducation;
}
public void setFormOfAducation(String formOfAducation) {
this.formOfAducation = formOfAducation;
}
@ManyToOne
@JoinColumn(name ="id_group")
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public String getStudentCourse() {
return studentCourse;
}
public void setStudentCourse(String studentCourse) {
this.studentCourse = studentCourse;
}
public String getStudentSpecializatio() {
return studentSpecializatio;
}
public void setStudentSpecializatio(String studentSpecializatio) {
this.studentSpecializatio = studentSpecializatio;
}
public String getStudentBookName() {
return studentBookName;
}
public void setStudentBookName(String studentBookName) {
this.studentBookName = studentBookName;
}
public String getStudentGender() {
return studentGender;
}
public void setStudentGender(String studentGender) {
this.studentGender = studentGender;
}
}
最佳答案
属性group
在Student
中的映射应该是:
@ManyToOne
@JoinColumn(name = "group_id")
private Group group;
您不能在字段和属性级别混合注释。将这些注释移至该字段,事情就会按您的预期进行。
关于java - org.hibernate.MappingException : Could not determine type for:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44475949/