在 Hibernate 中映射 SortedSet 的性能代价是多少?

发布于 2024-10-01 04:24:36 字数 354 浏览 0 评论 0原文

在我的一个映射类中,我有一个通过 hibernate 映射到数据库的 Set 字段。我现在需要根据某种逻辑对该集合进行排序,我将其写入新的 Comparator 实现中。我将字段类型更改为 SortedSet,将此 Comparator 作为属性添加到我的 hibernate 映射(XML,无注释),假设 Hibernate 从数据库检索所有对象,然后进行排序使用给定的比较器。

一位同事提出了这里隐藏性能代价的可能性,因为 Hibernate 实际上使用插入排序,这意味着它会为加载的每个对象多次调用 compare 方法。这是真的吗?映射排序集合是否存在其他性能问题?

In one of my mapped classes, I have a Set field mapped to the DB via hibernate. I now need this collection to be sorted according to some logic, which I wrote into a new Comparator implementation. I changed the field type to SortedSet, added this Comparator as an attribute to my hibernate mapping (XML, no annotations), assuming Hibernate retrieved all objects from the DB, then sorts using the given Comparator.

A colleague brought up the possibility that there is a performance price hidden here, as Hibernate actually uses insertion sort, meaning it calls the compare method numerous times for every object it loads. Is this true? Are there any other performance issues to mapping a sorted collection?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文