1

我使用 Hibernate3 和 Hibernate Tools 3.2.4 来生成 hbm.xml 和 java 文件,我想使用 List 而不是 HashSet(...)。我试图修改 hbm.xml 文件,将列表而不是设置。有什么方法可以指定要自动生成列表而不是 HashSet 的休眠工具?这是一个例子:

Java 类

public class Test implements java.io.Serializable {  

     private Long testId;  
     private Course course;  
     private String testName;  
     private Set<Question> questions = new HashSet<Question>( 0 );  
}

测试.hbm.xml:

<set name="questions" inverse="true" lazy="true" table="questions" fetch="select">  
  <key>  
    <column name="test_id" not-null="true" />  
  </key>  
  <one-to-many class="com.app.objects.Question" />
  ...
</set>

我以为我可以在“reveng.xml”文件中找到线索,但我失败了。

4

1 回答 1

1

好吧,<set>您没有尝试在 hbm.xml 中使用 a ,而是尝试使用 a <list>?请注意,您需要在集合表中使用索引列<list>(因为List是有序集合)。

尝试这样的事情:

<list name="questions" 
      inverse="true" 
      lazy="true" 
      table="questions" 
      fetch="select">  
  <key column name="test_id" not-null="true" />  
  <list-index column="sortOrder"/>
  <one-to-many class="com.app.objects.Question" />
</list>

请参阅第6.2 节。文档中的集合映射以获取完整详细信息。请特别注意第6.2.3 节。索引集合

于 2010-05-09T21:17:40.323 回答