我将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@Entitypublic 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@Entitypublic 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 omittedMain.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(); }
3 回答

慕工程0101907
TA贡献1887条经验 获得超5个赞
您正在使用字段访问策略(由@Id注释确定)。将任何与JPA相关的注释放在每个字段的上方,而不是getter属性的上方
@OneToMany(targetEntity=Student.class, mappedBy="college", fetch=FetchType.EAGER)
private List<Student> students;
添加回答
举报
0/150
提交
取消