0

For example I have a named query:

@NamedQuery(name = "Students", query = "SELECT s FROM Student WHERE s.active = 'Y' OR s.name= :name) 

Sometimes I wanna set the 'name' parameter with a value and sometimes not. Does it cause an error when I don't set it?

1

2 Answers 2

1

You have to set it always. Otherwise - create two queries - one with param, and one without. You can place the common part in a constant (static final)

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

Comments

0

I found a solution like this:

if (my test criteria){ query.setParameter("name", "name of a student"); } else { query.setParameter("name", " "); } 

I am setting the name parameter with whitespace character so it works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.