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

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>

 

你可能感兴趣的:(@@ManyToOne,@OneToOne)