更改 Hibernate 3 设置

发布于 2024-08-31 21:02:22 字数 780 浏览 3 评论 0原文

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

Java class

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

I use Hibernate3 and Hibernate Tools 3.2.4 to generate hbm.xml and java files and I want to use List instead of HashSet(...). I've tried to modify the hbm.xml files, putting list instead of set. Is there any way to specify to hibernate tools that I want to generate automatically a list not a HashSet?
This is an exemple:

Java class

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>

I thought that I could find a clue in the "reveng.xml" file, but I failed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰沐子 2024-09-07 21:02:22

那么,您是否尝试在 hbm.xml 中使用 ,而不是使用 ?请注意,您需要在集合表中有一个索引列才能使用 (因为 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.索引集合

Well, instead of using a <set> in your hbm.xml, did you try to use a <list>? Note that you'll need an index column in the collection table to use <list> (since List is an ordered collection).

Try something like that:

<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>

Refer to the section 6.2. Collection mappings in the documentation for full details. Pay a special attention to the section 6.2.3. Indexed collections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文