简体   繁体   English

findall休眠或条件和示例

[英]findall hibernate or Criteria and Example

In Hibernate, what is the best approach: 在Hibernate中,最好的方法是:

  1. to use findAll for datatable objects, return all the fields and extract only the relevant data, or use Criteria and Example to focus the results and the columns? 将findAll用于数据表对象,返回所有字段并仅提取相关数据,还是使用Criteria和Example集中结果和列?
  2. if the answer is based on table size - from which columns amount and row amount is it recommended to use each approach? 如果答案是基于表大小的,那么建议使用每种方法中的列数和行数?

I think only you can decide which approach to take based on your application. 我认为只有您可以根据自己的应用程序决定采用哪种方法。

  1. If you need a data from each object in the datatable it would be alot easier to retrieve all objects and extract the relevant data. 如果需要数据表中每个对象的数据,则检索所有对象并提取相关数据会容易得多。 If this incurs a sufferable performance overhead, then hibernate offers a bunch of optimizations to extract the data you need. 如果这会带来可观的性能开销,那么hibernate会提供一系列优化来提取所需的数据。 Remember that reading columns is alot faster than reading rows. 请记住,读取列比读取行快很多。 One such optimization could be to extract a list of id's which can be iterated over by the application which fetches the entries one by one, incurring an almost zero memory overhead with some tradeoff to the number of transactions. 一种这样的优化可能是提取一个ID列表,该ID可以由应用程序进行迭代,该应用程序逐个获取条目,从而导致几乎零的内存开销,并且需要对事务数量进行一些折衷。

  2. There is generally no recommended limit as it all depends on your application and table size. 通常没有建议的限制,因为这完全取决于您的应用程序和表的大小。 I would probably find another way if I the query spans over 10k objects, mostly due to memory concerns. 如果查询跨越超过1万个对象(主要是由于内存问题),我可能会找到另一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM