org.hibernate.MappingException:无法确定类型:

我将Hibernate用于项目中的所有CRUD操作。它不适用于一对多和多对一关系。它给了我下面的错误。


org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)]


然后我又看了这个视频教程。一开始对我来说很简单。但是,我不能使其工作。现在也说


org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)]


我在互联网上进行了一些搜索,有人告诉它Hibernate中的错误,有人说,通过添加@GenereatedValue可以清除此错误,但对我不起作用。


College.java


@Entity

public class College {

@Id

@GeneratedValue(strategy=GenerationType.AUTO)

private int collegeId;

private String collegeName;



private List<Student> students;


@OneToMany(targetEntity=Student.class, mappedBy="college", fetch=FetchType.EAGER)

public List<Student> getStudents() {

    return students;

}

public void setStudents(List<Student> students) {

    this.students = students;

}//Other gettters & setters omitted

学生.java


@Entity

public class Student {



@Id

@GeneratedValue(strategy=GenerationType.AUTO)

private int studentId;

private String studentName;



private College college;


@ManyToOne

@JoinColumn(name="collegeId")

public College getCollege() {

    return college;

}

public void setCollege(College college) {

    this.college = college;

}//Other gettters & setters omitted

Main.java:


public class Main {


private static org.hibernate.SessionFactory sessionFactory;


  public static SessionFactory getSessionFactory() {

    if (sessionFactory == null) {

      initSessionFactory();

    }

    return sessionFactory;

  }


  private static synchronized void initSessionFactory() {

    sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();


  }


蝴蝶刀刀
浏览 358回答 3
3回答

慕工程0101907

您正在使用字段访问策略(由@Id注释确定)。将任何与JPA相关的注释放在每个字段的上方,而不是getter属性的上方@OneToMany(targetEntity=Student.class, mappedBy="college", fetch=FetchType.EAGER)private List<Student> students;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java