开发者

hibernate creates problem for table with composite primary key while generating hibernate classes with eclipse

开发者 https://www.devze.com 2022-12-14 20:52 出处:网络
I have 2 tables as given below. feedback_answer question_id number(primary key) answer_id number (primary key)

I have 2 tables as given below.


feedback_answer

question_id number(primary key)

answer_id number (primary key)

answer_en varchar2(255)

answer_it varchar2(255)


user_feedback

verification_id number(primary key)

question_id number(foreign key - feedback_answer)

answer_id number(foreign key - feedback_answer)


I am getting following error for hibernate after hibernate class generation in eclipse

ERROR :: 2009-12-29 14:57:34,093 ERROR java.lang.Class (http-8080-2) - Initial SessionFactory creation failed.org.hibernate.MappingException: Foreign key (FK39E53D791A62BD16:USER_FEEDBACK [QUESTION_ID])) must have same number of columns as the referenced primary key (FEEDBACK_ANSWER [QUESTION_ID,ANSWER_ID])

Following is the java code for feedback_answer

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

}

Following is the hibernate code for 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="que开发者_开发知识库stionId" 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>

Can anyone help me regarding the matter?

Thanks.

amar4kintu


to solve above problem.. I changed my table structure to take one primary key only.. and it solved my problem.. I had to do that because I do not have much time as I need to complete work in time...

so thanks to all who tried to help me out here..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号