2010-05-09 89 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