懒惰加载一组自定义对象时出现Hibernate Mapping问题

时间:2017-06-24 17:22:02

标签: java xml hibernate

我试图使用Hibernate从我的数据库中读取,但我遇到了问题。任何帮助,将不胜感激。这与问题对象中有一组答案这一事实有关,而且我不确定这对该主题的影响。

List<Question> questions = session
                             .createQuery("from Question where topic = :id")
                             .setParameter("id", topic) 
                             .list();

代码:

<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 class="cdd.model.User" column="submitted_by" name="submittedBy" not-null="true" lazy = "false"/>
  <many-to-one  class="cdd.model.Topic" column="question_topic" name="topic" not-null="true" lazy = "false"/>
  <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"/>
  <property column = "approved" name = "approved" type = "org.hibernate.type.BooleanType"/>

  <set cascade="all" name="answers"  >
    <key column="question_id" not-null="true" lazy = "false" />
    <one-to-many class="cdd.model.Answer"/>
  </set>
</class>

已映射的Java类:

public class Question {
    UUID questionID;
    User submittedBy;
    Topic topic;
    String title;
    String correctAnswer;
    Timestamp dateSubmitted; 

    boolean approved;

    Set<Answer> answers;

    /*Constructor, Getters and Setters*/
}

错误:

XML validation started.
Checking file:/Users/rhamblin/Desktop/CDDExamGen/src/hibernateMapping.hbm.xml...
Attribute "lazy" must be declared for element type "key". [69] 
XML validation finished.

0 个答案:

没有答案