下面是报错信息的主要部分
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: com.test.entity.Dept.workers
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.test.entity.Worker.deptId in com.test.entity.Dept.workers
上面的大意是在Dept实体类中,通过deptId对workers分类失败,这个deptId是未知的实体类属性
那么我为什么会报这个错呢
首先要明确这两个实体类的关系,Dept和Worker是一对多的关系,因此实体类中要描述两者的关系,我是在这个过程中出错的,见下图