I have a web app build with Hibernate. In one page, I have one submit button with 5 inputs
* field1
* field2
* field3
* field4
* field5
When all the inputs are null, I make a simple querry
Code:
Query query = session.createQuery("from MyTable");
but when I have at least one input not null, I must create the search query. Let's say, the field1 is not null:
Code:
Query query = session.createQuery("from MyTable where field1= :field1");
query.setParameter("field1", field1);
But I need to check every single input and I need to create the query String based on this thing. It's really a pain in the neck for 2 fields, but for 5...
What is the smartest, easiest way to create the search query in this situation?