This article to introduce hibernate filter, maybe a lot of people do not know hibernate filter, no relationship, after reading this article you certainly have a lot of harvest, hope this article can teach you more things.
Hibernate3 adds the ability to use a predefined Hibernate filter criteria (filter criteria) for a class or collection. Filter conditions are equivalent to defining a constraint clause that is very similar to a "where" property on a class and various collections, but a filter condition can take parameters.
The application can decide at run time whether to enable a given hibernate filter and what parameter values to use. Filters are used much like database views, except to determine what parameters to use in an application.
To use a filter, you must first define it in the appropriate mapping node. To define a filter, use the <filter-def/> node located within the
<filter-def name="myFilter">
<filter-param name="myFilterParam" type="string"/>
</filter-def>
Once defined, you can use this filter in a class:
<class name="myClass" ...>
...
<filter name="myFilter" condition=":myFilterParam = MY_FILTERED_COLUMN"/>
</class>
You can also use it in a collection:
<set ...>
<filter name="myFilter" condition=":myFilterParam = MY_FILTERED_COLUMN"/>
</set>
You can use a filter in more than one class or collection, or you can use multiple filters in a class or collection.
The methods that are used in the Session object are: Enablefilter (string filtername), Getenabledfilter (string filtername), and Disablefilter (string FilterName). The default in session is not to enable filters, which must be explicitly enabled through the Session.enabledfilter () method. This method returns an instance of the enabled filter. The filter defined above is an example:
Session.enablefilter ("Myfilter"). Setparameter ("Myfilterparam", "Some-value");