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 ")
文章列表