【问题标题】:Changing the Hibernate 3 settings更改休眠 3 设置
【发布时间】:2011-02-17 10:47:09
【问题描述】:

我使用 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 );  
}

Test.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”文件中找到线索,但失败了。

【问题讨论】:

    标签: hibernate orm settings reverse-engineering hbm


    【解决方案1】:

    那么,您是否尝试在 hbm.xml 中使用 &lt;list&gt;,而不是使用 &lt;set&gt;?请注意,您需要集合表中的索引列才能使用&lt;list&gt;(因为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. Collection mappings 部分以获取完整详细信息。特别注意6.2.3. Indexed collections部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-04
      • 1970-01-01
      • 2015-05-28
      • 2011-06-06
      相关资源
      最近更新 更多