5

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;
}

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.