问题
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:
- Hibernate Data Filter Example – XML And Annotation
- Hibernate Criteria Examples
来源:https://stackoverflow.com/questions/18891607/difference-between-filters-and-criteria-in-hibernate