2010-05-09 102 views
1

我使用Hibernate3和Hibernate Tools 3.2.4來生成hbm.xml和java文件,我想使用List而不是HashSet(...)。我試圖修改hbm.xml文件,放置列表而不是set。有什麼辦法來指定休眠工具,我想自動生成一個列表不是一個HashSet? 這是個例:更改休眠3設置

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」 文件線索,但我失敗了。

回答

1

那麼,您是否嘗試使用<list>?而不是在您的hbm.xml中使用<set>?請注意,您需要收集表中的索引列才能使用<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. Collection mappings的文檔中的全部細節。請特別注意部分6.2.3. Indexed collections