ERROR [ContainerBackgroundProcessor[StandardEngine[Catalina]]] ContextLoader.initWebApplicationContext(220) | Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [spring/applicationContext-dao.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [F:\webserver\apache-tomcat-6.0.32\webapps\blognms\WEB-INF\classes\spring\applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException:
问题重点:
 Foreign key (FKAECBABBE3114B171:ibokee_report_comment [post])) must have same number of columns as the referenced primary key (ibokee_wb_postcomment [postID,postComments_id])

@Entity
@Table(name = "ibokee_report_comment")
@Searchable
@XmlRootElement
public class ReportComment implements Serializable { private static final long serialVersionUID = 1L;

private Long id;
/** 日志评论 */
private ArticleComment article;
/** 照片评论 */
private PhotoComment photo;
/** 微博评论 */
private PostComment post; @Id
@GeneratedValue(strategy = GenerationType.AUTO)
@SearchableId
public Long getId() {
return id;
} public void setId(Long id) {
this.id = id;
} @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "article")
public ArticleComment getArticle() {
return article;
} public void setArticle(ArticleComment article) {
this.article = article;
} @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "photo")
public PhotoComment getPhoto() {
return photo;
} public void setPhoto(PhotoComment photo) {
this.photo = photo;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "post")
public PostComment getPost() {
return post;
} public void setPost(PostComment post) {
this.post = post;
}}
@Entity
@Table(name = "ibokee_wb_postcomment")
@Searchable
@XmlRootElement
public class PostComment implements Serializable { private static final long serialVersionUID = 1L; private Integer id; private Post post; private User user; private String content; private Date createTime; private Boolean del = Boolean.FALSE; /** 评论回复 */
private PostComment parent; public PostComment() { } @Id
@GeneratedValue(strategy = GenerationType.AUTO)
@SearchableId
public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "post")
public Post getPost() {
return post;
} public void setPost(Post post) {
this.post = post;
} @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user")
public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
} @Column
public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} @Column
public Date getCreateTime() {
return createTime;
} public void setCreateTime(Date createTime) {
this.createTime = createTime;
} @Column
public Boolean getDel() {
return del;
} public void setDel(Boolean del) {
this.del = del;
} @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "parent")
public PostComment getParent() {
return parent;
} public void setParent(PostComment parent) {
this.parent = parent;
}}

解决方案 »

  1.   

    applicationContext-dao.xml
    里sessionfactory配置错了你打红字的不是问题关键,因为sessionfactory配置里的初始化方法错了,才导致你那红字的错误。
    好好看下 applicationContext-dao.xml 怎么配置的。
      

  2.   

     Error creating bean with name 'sessionFactory' defined in file [F:\webserver\apache-tomcat-6.0.32\webapps\blognms\WEB-INF\classes\spring\applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException:
    这错了 hiberdate的注解真的是没有用过哈哈哈很高级啊 学习了
      

  3.   

    楼主,你这代码的错误提示是加载完毕那个xml文件的时候就这样的错误,原因出在你的外键上,一定是你的数据不对,请楼主仔细查找一下数据!!
      

  4.   

    答案是将上面的ManyToOne() 改成 OneToMany(mappedBy="",fetch = FetchType.EAGER)
    就可以了,当初我问这题目的时候,就已经吧问题重点用红色字体勾出来了单就是每一个人说到哪里,最有意思的是,#1楼,居然说不是哪里的问题
      

  5.   

    ManyToOne()这里有问题, 
      @ManyToOne(fetch = FetchType.EAGER)
        @JoinColumn(name = "post")
    改改
    @JoinColumn(name = "post" class="类名" column="外键ID")不过LZ好象manyToOne和onetomany有点混淆,