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