您的位置:首页 > 移动开发

mappedBy reference an unknown target entity property解决方法

2014-06-17 21:44 453 查看
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 ")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐