Hibernate AnnotationException

时间:2013-05-07 16:26:11

标签: hibernate

使用Hibernate Annotations构建我的数据库我得到一个错误:

Exception in thread "main" org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: de.hof.university.spj.entities.CrewMember.TBL_SPJ_CREW_MOVIE in de.hof.university.spj.entities.CrewMovie.crewMember
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:708)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:668)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1593)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1350)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at de.hof.university.spj.model.DatabaseBuilder.configureSessionFactory(DatabaseBuilder.java:40)
at de.hof.university.spj.model.DatabaseBuilder.<init>(DatabaseBuilder.java:28)
at de.hof.university.spj.main.Main.main(Main.java:46)

我实际上不知道我做错了什么,找到一个解决方案似乎并不容易在那里存在的hibernate问题的丛林中......

我的课程:

船员会员

@Entity
@Table(name="TBL_SPJ_CREWMEMBER")
public class CrewMember implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = 1L;
/**
 * 
 */
@Id
@GeneratedValue(strategy=IDENTITY)
@Column(name="CREWMEMBER_ID", unique=true)
private int crewMemberId = 0;
/**
 *
 */
@Column(name="CREWMEMBER_PEOPLE_ID")
private int personID = 0;
/**
 *
 */
@Column(name="CREWMEMBER_DEPARTMENT")
private String department = "";
/**
 *
 */
@Column(name="CREWMEMBER_JOB")
private String job = "";

/**
 * 
 */
public CrewMember() {}

/**
 * @return the crewMemberId
 */
public int getCrewMemberId() {
    return crewMemberId;
}
/**
 * @param crewMemberId the crewMemberId to set
 */
public void setCrewMemberId(int crewMemberId) {
    this.crewMemberId = crewMemberId;
}
/**
 * @return the person
 */
public int getPersonID() {
    return personID;
}
/**
 * @param person the person to set
 */
public void setPersonID(int personID) {
    this.personID = personID;
}
/**
 * @return the departement
 */
public String getDepartment() {
    return department;
}
/**
 * @param departement the department to set
 */
public void setDepartment(String department) {
    this.department = department;
}
/**
 * @return the job
 */
public String getJob() {
    return job;
}
/**
 * @param job the job to set
 */
public void setJob(String job) {
    this.job = job;
}
/**
 * 
 */
public String toString() {
    return personID + "-" + department + "-" + job;
}
}

CrewMovie:

@Entity
@Table(name="TBL_SPJ_CREW_MOVIE")
public class CrewMovie implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = 1L;
/**
 * 
 */
@Id
@GeneratedValue(strategy=IDENTITY)
@Column(name="CREW_MOVIE_ID", unique=true)
private int crewId = 0;
/**
 *
 */
@OneToMany(fetch=FetchType.LAZY, mappedBy="TBL_SPJ_CREW_MOVIE")
private List<CrewMember> crewMember = null;

/**
 * 
 */
public CrewMovie() {}

/**
 * @return the crewId
 */
public int getCrewId() {
    return crewId;
}
/**
 * @param crewId the crewId to set
 */
public void setCrewId(int crewId) {
    this.crewId = crewId;
}
/**
 * @return the crewMember
 */
public List<CrewMember> getCrewMember() {
    return crewMember;
}
/**
 * @param crewMember the crewMember to set
 */
public void setCrewMember(List<CrewMember> crewMember) {
    this.crewMember = crewMember;
}
/**
 * 
 */
public String toString() {
    String returning = "Crew: ";

    if(crewMember != null && crewMember.size() > 0) {
        for(CrewMember member: crewMember) {
            returning += member.toString();
            returning += ", ";
        }
    }

    returning += "\n";

    return returning;
}
}

1 个答案:

答案 0 :(得分:0)

听起来你想要一个单向映射,你只能在CrewMovie上有注释。需要将一列添加到TBL_SPJ_CREWMEMBER表以支持此列。在我的示例中,我将J_CREW_MOVIE_ID列添加到其中。

@Entity
@Table(name="TBL_SPJ_CREW_MOVIE")
public class CrewMovie implements Serializable {

    @Id
    @GeneratedValue(strategy=IDENTITY)
    @Column(name="CREW_MOVIE_ID", unique=true)
    private int crewId = 0;

    @OneToMany
    @JoinColumn(name="J_CREW_MOVIE_ID", referencedColumnName="CREW_MOVIE_ID")
    private List<CrewMember> crewMember = null;
}