日期:2014-05-17  浏览次数:20762 次

Hibernate 关于注解的错误,请教下
[code=Java][/code]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])


Java code

@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;
    }

}






Java code

@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() {