java - org.hibernate.MappingException : Could not determine type for:

标签 java hibernate jpa

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;
    }
}

最佳答案

属性groupStudent中的映射应该是:

@ManyToOne
@JoinColumn(name = "group_id")
private Group group;

您不能在字段和属性级别混合注释。将这些注释移至该字段,事情就会按您的预期进行。

关于java - org.hibernate.MappingException : Could not determine type for:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44475949/

相关文章:

java - 使用注释一对多不添加列(hibernate)

java - Hibernate可以批量数据库查询二级缓存中集合未命中的情况吗?

java - 如何使用@EmbeddedId 在两个表之间进行映射?

java - 用户登录时启用页面上的按钮/GWT

java - 在二叉树中计算最大和时出现问题

java - Spring on Glassfish - 记录 Hibernate 参数?

java - 如何使用 HQL (Hibernate) 查询日期的平均天数差异?

java - 数组对角邻域分析与排序

java - 使用循环输出 ASCII 菱形

Java EE RESTful 服务 JSON 编码 415 状态与 @Xml* 注释