当前位置: 代码迷 >> Java Web开发 >> spring2.5+hibernate3.6+struts2.2哪位大侠能把忙找找错误??不胜感激
  详细解决方案

spring2.5+hibernate3.6+struts2.2哪位大侠能把忙找找错误??不胜感激

热度:881   发布时间:2011-07-25 13:17:18.0
spring2.5+hibernate3.6+struts2.2哪位大侠能把忙找找错误??不胜感激
spring配置文件:
        <property name="annotatedClasses">
            <list>
                <value>com.pmmp.model.Blog</value>
                <value>com.pmmp.model.Comment</value>
            </list>
        </property>

Blog类代码:
@Entity
public class Blog {
    private int id;                //博文的唯一标记
    private List<Comment> commentList;    //评论列表

    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @OneToMany(mappedBy="blog")
    public List<Comment> getCommentList() {
        return commentList;
    }
    public void setCommentList(List<Comment> commentList) {
        this.commentList = commentList;
    }
}
Comment类的代码:
public class Comment {
    private int id;                //评论的唯一标记
    private Blog blog;            //评论所属的博文

    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    @ManyToOne
    @JoinColumn(name="blog_id")
    public Blog getBlog() {
        return blog;
    }
    public void setBlog(Blog blog) {
        this.blog = blog;
    }
}

错误提示:
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.pmmp.model.Blog.commentList[com.pmmp.model.Comment]
    at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1168)
    at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:693)
    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:628)
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)
    at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1686)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1393)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
    ... 52 more


[ 本帖最后由 huang1003 于 2011-7-25 13:19 编辑 ]
搜索更多相关主题的帖子: spring  配置文件  private  不胜感激  property  

----------------解决方案--------------------------------------------------------
Use of @OneToMany or @ManyToMany targeting an unmapped class: com.pmmp.model.Blog.commentList[com.pmmp.model.Comment]

错误信息已经很清楚了啊。
你可以去看看你的配置文件是否有问题!
----------------解决方案--------------------------------------------------------
是Blog 类的Blog.hbm.xml配置文件中commentList属性与Comment 类关联时出现了问题,想解决问题请把你的配置问题贴出来
----------------解决方案--------------------------------------------------------
Use of @OneToMany or @ManyToMany targeting an unmapped class: com.pmmp.model.Blog.commentList[com.pmmp.model.Comment]
就是这个问题  
Blog 和 Comment 关系出现问题啦

[ 本帖最后由 jfei 于 2011-9-8 14:48 编辑 ]
----------------解决方案--------------------------------------------------------
回复 楼主 huang1003
Comment类头上少一个@Entity呀
----------------解决方案--------------------------------------------------------
of @OneToMany or @ManyToMany targeting an unmapped class: com.pmmp.model.Blog.commentList,类型不匹配。
----------------解决方案--------------------------------------------------------
  相关解决方案