Hibernate可以返回除列表以外的其他结果对象的集合吗? [英] Can Hibernate return a collection of result objects OTHER than a List?

查看:81
本文介绍了Hibernate可以返回除列表以外的其他结果对象的集合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hibernate API是否支持List之外的集合形式的对象结果集?

例如,我有一个运行数十万次迭代的进程,以便为客户端创建一些数据。此过程使用Value表中的记录(例如)为每个迭代创建此输出。

对于列表,我必须遍历整个列表才能找到某个值,这很贵。我希望能够返回一个TreeMap并以编程方式指定一个键,以便我可以在集合中搜索我需要的特定值。 Hibernate能为我做这件事吗?

解决方案

我假设你指的是 Query.list() 方法。如果是这样:否,除了 List 之外,没有办法返回顶级结果。如果您收到的结果太多,为什么不向数据库发出更受限制的查询?如果查询很难限制,可以用Hibernate的 List 的内容填充自己的 Map ,然后丢弃该列表。


Does the Hibernate API support object result sets in the form of a collection other than a List?

For example, I have process that runs hundreds of thousands of iterations in order to create some data for a client. This process uses records from a Value table (for example) in order to create this output for each iteration.

With a List I would have to iterate through the entire list in order to find a certain value, which is expensive. I'd like to be able to return a TreeMap and specify a key programmatically so I can search the collection for the specific value I need. Can Hibernate do this for me?

解决方案

I assume you are referring to the Query.list() method. If so: no, there is no way to return top-level results other than a List. If you are receiving too many results, why not issue a more constrained query to the database? If the query is difficult to constrain, you can populate your own Map with the contents of Hibernate's List and then throw away the list.

这篇关于Hibernate可以返回除列表以外的其他结果对象的集合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆