Hibernate Filter Usage Tips

Source: Internet
Author: User
Tags filter define what parameter

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");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.