【发布时间】:2017-10-21 05:06:48
【问题描述】:
我得到的错误是 " org.hibernate.MappingException: 实体映射中的重复列:cdd.model.Answer 列:answer_id(应该使用 insert="false" update="false" 进行映射)" 。但是,当我将这些作为属性时,我得到了错误:“必须为元素类型“id”声明属性“插入”。”
任何帮助将不胜感激。
类:
public class Answer {
UUID answerID;
String content;
//constructors and getters and setters
}
表:
CREATE TABLE IF NOT EXISTS answer (
answer_id uuid NOT NULL ,
content text NOT NULL,
primary key(answer_id)
);
休眠映射文件:
<!-->==== Answer ====<!-->
<class name="cdd.model.Answer" table="answer" >
<id column="answer_id" name="answerID"
type="org.hibernate.type.PostgresUUIDType"
insert="false" update="false">
<generator class="org.hibernate.id.UUIDGenerator"/>
</id>
<property column="content" name="content" type="org.hibernate.type.TextType"/>
</class>
注意 我有一个问题类,其中一个问题有一组答案。这是我使用的映射。我发布它是因为我遇到的错误可能是因为我如何映射这种 一对多 关系(我不确定)。
<!-- ==== Question ==== -->
<class name="cdd.model.Question" table="question">
<id column="question_id" name="questionID" type="org.hibernate.type.PostgresUUIDType">
< generator class="org.hibernate.id.UUIDGenerator"/>
</id>
<many-to-one column="submitted_by" name="submittedBy" not-null="true"/>
<many-to-one column="parentCategory" name="parentCategory" not-null="true"/>
<property column="title" name="title" type="org.hibernate.type.TextType"/>
<property column="correct_answer" name="correctAnswer" type="org.hibernate.type.TextType"/>
<property column="date_submitted" name="dateSubmitted" type="org.hibernate.type.TimestampType"/>
<set cascade="all" name="answers" table="answer">
<key column="answer_id" not-null="true"/>
<one-to-many class="cdd.model.Answer"/>
</set>
<join inverse="true" optional="true" table="category_questions">
<key column="question_id"/>
</join>
<join inverse="true" optional="true" table="accepted_questions_by_user">
<key column="question_id"/>
</join>
</class>
【问题讨论】:
标签: java database hibernate orm mapping