0

我浏览了许多视频和教程,解释了如何使用注释机制在休眠中配置一对多关系。我仍然收到此错误。

错误是:org.hibernate.AnnotationException:使用@OneToMany 或@ManyToMany 瞄准未映射的类:bean.Professor.coursesAssigned[bean.Course] 使用@OneToMany 或@ManyToMany 瞄准未映射的类:bean.Professor.coursesAssigned[豆.课程]

我的课程是:

教授.java

    package bean;

    import java.util.Set;

    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.OneToMany;

    @Entity
    public class Professor extends User{

        @OneToMany(targetEntity = Course.class, mappedBy = "assignedProfessor", 
                cascade = CascadeType.ALL , fetch = FetchType.LAZY)
        private Set<Course> coursesAssigned;
    }

course.java 是:

    package bean;

    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;

    public class Course {

        private Integer courseId;
        private String courseName;

        @ManyToOne(targetEntity = Professor.class)
        @JoinColumn(name = "professor_join")
        private Professor assignedProfessor;
    }
4

1 回答 1

5
org.hibernate.AnnotationException: 
Use of @OneToMany or @ManyToMany targeting an unmapped class: bean.Professor.coursesAssigned[bean.Course] 
Use of @OneToMany or @ManyToMany targeting an unmapped class: bean.Professor.coursesAssigned[bean.Course]

异常已经说明了原因。@OneToMany并且@ManyToMany只能在其类是映射类的属性上进行注释。如果一个类被注释 @Entity并包含<mapping class>在配置文件中或以编程方式包含在配置实例中,则认为它们是映射的。

@Entity所以,我相信你在课堂上打分后异常就会消失Course

于 2012-04-12T03:39:53.727 回答