hibernate3.2 @OneToMany异常
TbComment 类和TbMyDiary 类之间是多对一的关系.
package com.hj.vo;// Generated Mar 1, 2008 12:07:56 AM by Hibernate Tools 3.2.0.CR1import java.util.Date;import java.util.HashSet;import java.util.Set;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.OneToMany;/** * TbMyDiary generated by hbm2java */@Entitypublic class TbMyDiary implements java.io.Serializable {/** * */private static final long serialVersionUID = 5391171835504714756L;private int mainid;private String loginName;private String title;private String weather;private String mood;private String content;private Date diarytime;private Integer openLevel;private Integer viewNum;private Integer status;private Set<TbComment> tbComments=new HashSet(0);public Integer getStatus() {return status;}public void setStatus(Integer status) {this.status = status;}public TbMyDiary() {}public TbMyDiary(int mainid) {this.mainid = mainid;}public TbMyDiary(int mainid, int FUserid, String loginName, String title,String weather, String mood, String content, Date diarytime,Integer openLevel) {this.mainid = mainid;this.loginName = loginName;this.title = title;this.weather = weather;this.mood = mood;this.content = content;this.diarytime = diarytime;this.openLevel = openLevel;}@Id @GeneratedValuepublic int getMainid() {return this.mainid;}public void setMainid(int mainid) {this.mainid = mainid;}public String getLoginName() {return this.loginName;}public void setLoginName(String loginName) {this.loginName = loginName;}public String getTitle() {return this.title;}public void setTitle(String title) {this.title = title;}public String getWeather() {return this.weather;}public void setWeather(String weather) {this.weather = weather;}public String getMood() {return this.mood;}public void setMood(String mood) {this.mood = mood;}public String getContent() {return this.content;}public void setContent(String content) {this.content = content;}public Date getDiarytime() {return this.diarytime;}public void setDiarytime(Date diarytime) {this.diarytime = diarytime;}public Integer getOpenLevel() {return this.openLevel;}public void setOpenLevel(Integer openLevel) {this.openLevel = openLevel;}public Integer getViewNum() {return viewNum;}public void setViewNum(Integer viewNum) {this.viewNum = viewNum;}@OneToMany(mappedBy="myDiary")public Set<TbComment> getTbComments() {return tbComments;}public void setTbComments(Set<TbComment> tbComments) {this.tbComments = tbComments;}}在执行Session session=HibernateSessionFactory.getSession();时报如下异常.
%%%% Error Creating SessionFactory %%%%
org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.hj.vo.TbMyDiary.tbComments[com.hj.vo.TbComment]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1068)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:600)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:541)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1136)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at com.hj.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:63)
at com.hj.HibernateSessionFactory.getSession(HibernateSessionFactory.java:45)
at com.hj.dao.CommentDAO.insert(CommentDAO.java:21)
at com.hj.dao.CommentDAO.main(CommentDAO.java:14) 1 楼 Readonly 2008-04-16 检查大小写错误 2 楼 ajjjian 2008-04-16 @OneToMany(mappedBy="myDiary") 里的mappedBy的值不是TbComment类里的TbMyDiary对象名嘛?