为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

蝴蝶刀刀 2019-10-09 15:21:51
我将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;


查看完整回答
反对 回复 2019-10-09

添加回答

代码语言

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号