【问题标题】:What are the intended use cases for CustomCollectionType vs. UserCollectionType in Hibernate?Hibernate 中 CustomCollectionType 与 UserCollectionType 的预期用例是什么?
【发布时间】:2014-04-16 03:30:07
【问题描述】:

CustomCollectionTypeUserCollectionType 的预期用例是什么?

如果我想在 Hibernate 中使用我自己的集合,我应该使用哪一个?

This example 使用UserCollectionType。我找不到使用CustomCollectionType 的示例,如何使用CustomCollectionType

使用CustomCollectionTypeUserCollectionType 有哪些优点/缺点?

【问题讨论】:

    标签: java hibernate collections orm persistence


    【解决方案1】:

    UserCollectionType 用于当您希望在处理持久性时依赖 Hibernate 的集合处理,但希望向持久对象的客户端公开不同的类时。例如,如果您有一个 Auction 和一个一对多的 Bids,您可能希望 Hibernate 在持久化时将其视为一个集合,但您可能希望 getBids() 返回一个 FastSet(如您的链接中所示)。

    CustomCollectionType 用于当您想要使用 PersistentCollection 的新实现以完全不同的方式以不同的语义持久化集合时。除了更改某些 Hibernate 框架行为之外,我不确定您何时真正想要这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-30
      • 2013-05-31
      • 1970-01-01
      • 2012-09-23
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 2016-11-03
      相关资源
      最近更新 更多