我将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();
}
慕工程0101907
相关分类