difference between filters and criteria in hibernate

北城余情 提交于 2021-02-07 20:53:40

问题


What is the difference between filters and criteria in hibernate? criteria is used to filter the records by greater than,less than or equal etc.It is kind of filters.Can somebody show me what is difference by simple example


回答1:


Short answer:

  • A filter allows you to define a restriction clause similar to the existing "where" attribute available on the class and various collection elements. These filter conditions, however, can be parameterized. The application can then decide at runtime whether certain filters should be enabled and what their parameter values should be. Filters can be used like database views, but they are parameterized inside the application.

  • Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens where there is a variable number of conditions to be placed upon the result set.

For practical examples:

  1. Hibernate Data Filter Example – XML And Annotation
  2. Hibernate Criteria Examples


来源:https://stackoverflow.com/questions/18891607/difference-between-filters-and-criteria-in-hibernate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!