欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.lyl

程序员文章站 2022-03-02 13:32:30
...
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.lyl.entity.Grade.school references an unknown entity: com.lyl.entity.School
	at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:56)
	at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:474)
	at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:295)
	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
	... 26 more

 

原因有二:

(1) 被引用的类的class上没添@Entity注解

(2)没有添sessionFactory的annotatedClasses属性列表中去或者是<mapping-class>中去

 <property name="annotatedClasses">
   <list>
    <value>com.lyl.entity.Grade</value>
    <value>com.lyl.entity.Student</value>
   </list>
  </property>