【问题标题】:hibernate creates problem for table with composite primary key while generating hibernate classes with eclipsehibernate 在使用 eclipse 生成休眠类时为具有复合主键的表创建问题
【发布时间】:2009-12-29 11:29:26
【问题描述】:

我有 2 个表格,如下所示。


feedback_answer

question_id 编号(主键)

answer_id 编号(主键)

answer_zh varchar2(255)

answer_it varchar2(255)


用户反馈

verification_id 编号(主键)

question_id 编号(外键 - feedback_answer)

answer_id 号码(外键 - feedback_answer)


在 Eclipse 中生成休眠类后,我收到以下休眠错误

错误:: 2009-12-29 14:57:34,093 错误 java.lang.Class (http-8080-2) - Initial SessionFactory creation failed.org.hibernate.MappingException: Foreign key (FK39E53D791A62BD16:USER_FEEDBACK [QUESTION_ID])) 必须具有相同的数字列作为引用的主键 (FEEDBACK_ANSWER [QUESTION_ID,ANSWER_ID])

下面是feedback_answer的java代码

public class FeedbackAnswer implements java.io.Serializable {

private FeedbackAnswerId id;
private FeedbackQuestion feedbackQuestion;
private String answerEn;
private String answerIt;
private Set<Verification> verifications = new HashSet<Verification>(0);

public FeedbackAnswer() {
}

public FeedbackAnswer(FeedbackAnswerId id, FeedbackQuestion feedbackQuestion) {
    this.id = id;
    this.feedbackQuestion = feedbackQuestion;
}

public FeedbackAnswer(FeedbackAnswerId id,
        FeedbackQuestion feedbackQuestion, String answerEn,
        String answerIt, Set<Verification> verifications) {
    this.id = id;
    this.feedbackQuestion = feedbackQuestion;
    this.answerEn = answerEn;
    this.answerIt = answerIt;
    this.verifications = verifications;
}

public FeedbackAnswerId getId() {
    return this.id;
}

public void setId(FeedbackAnswerId id) {
    this.id = id;
}

public FeedbackQuestion getFeedbackQuestion() {
    return this.feedbackQuestion;
}

public void setFeedbackQuestion(FeedbackQuestion feedbackQuestion) {
    this.feedbackQuestion = feedbackQuestion;
}

public String getAnswerEn() {
    return this.answerEn;
}

public void setAnswerEn(String answerEn) {
    this.answerEn = answerEn;
}

public String getAnswerIt() {
    return this.answerIt;
}

public void setAnswerIt(String answerIt) {
    this.answerIt = answerIt;
}

public Set<Verification> getVerifications() {
    return this.verifications;
}

public void setVerifications(Set<Verification> verifications) {
    this.verifications = verifications;
}

}

以下是 feedback_answer 的休眠代码

<hibernate-mapping>
<class name="com.certilogo.inspect.backend.FeedbackAnswer" table="FEEDBACK_ANSWER" schema="SCOTT">
    <composite-id name="id" class="com.certilogo.inspect.backend.FeedbackAnswerId">
        <key-property name="answerId" type="long">
            <column name="ANSWER_ID" precision="22" scale="0" />
        </key-property>
        <key-property name="questionId" type="long">
            <column name="QUESTION_ID" precision="22" scale="0" />
        </key-property>
    </composite-id>
    <many-to-one name="feedbackQuestion" class="com.certilogo.inspect.backend.FeedbackQuestion" update="false" insert="false" fetch="select">
        <column name="QUESTION_ID" precision="22" scale="0" not-null="true" />
    </many-to-one>
    <property name="answerEn" type="string">
        <column name="ANSWER_EN" />
    </property>
    <property name="answerIt" type="string">
        <column name="ANSWER_IT" />
    </property>
    <set name="verifications" inverse="true" table="USER_FEEDBACK">
        <key>
            <column name="ANSWER_ID" precision="22" scale="0" />
            <column name="QUESTION_ID" precision="22" scale="0" />
        </key>
        <many-to-many entity-name="com.certilogo.inspect.backend.Verification">
            <column name="VERIFICATION_ID" precision="22" scale="0" not-null="true" unique="true" />
        </many-to-many>
    </set>
</class>

谁能帮我解决这个问题?

谢谢。

amar4kintu

【问题讨论】:

  • 好的.. 我不知道我必须接受一个答案.. 但是如果没有一个答案能满足您的问题.. 有什么规定吗?我将接受可能对我的问题最有帮助的答案。感谢您的建议。

标签: java eclipse hibernate struts


【解决方案1】:

为了解决上述问题..我将表结构更改为仅使用一个主键..它解决了我的问题..我不得不这样做,因为我没有太多时间,因为我需要及时完成工作。 ..

非常感谢所有在这里尝试帮助我的人..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    相关资源
    最近更新 更多