How to programmatically achieve the same result (as the following annotation would achieve)? Or injecting the value 'SMITH' in a spring configuration file?
@Filter(name="smithFilter", condition="LAST_NAME = 'SMITH'")
public String getLastName()
{
return this.lastName;
}
Just define a FilterDef with the parameters the filter condition will receive:
@FilterDef(name = "smithFilter", parameters = {@ParamDef(name = "lastName", type = "string")})
@Filter(name="smithFilter", condition="LAST_NAME = :lastName")
As you also used the word "programmatically", you may also want to know that you can set the parameter based on other inputs, like this:
session.enableFilter("smithFilter").setParameter("lastName", "SMITH");
More details in Hibernate documentation:
http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#objectstate-filters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With