findall hibernate or Criteria and Example
In Hibernate, what is the best approach:
- 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?
- if the answer is based 开发者_StackOverflow社区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.
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. 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.
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.
精彩评论