mappedBy reference an unknown target entity property解决方法


Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleDaoImpl': Injection of resource methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.wangzhe.model.Keyword.Articles in com.wangzhe.model.Article.keywords

 

上面是错误的关键部分

  错误原因:在one-to-many注解配置: @OneToMany (mappedBy = "Articles"),mappedBy指向的是要关联的属性,而不是要关联的类,
        如果这样配置,hibernate则会找com.wangzhe.model.Keyword类下面的Articles 属性。但实际上没有这个属性,就会报上面的异常
   方法:指定到实际关联的属性:即:@OneToMany (mappedBy = "articles ")


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM