This is the same question as:
How to dynamically generate SQL query based on user's selections?
The only difference is, that I\'m interested in seeing soluti
If you want to do this in JPA 1.X, you can use custom query builder as described here http://rrusin.blogspot.com/2010/02/jpa-query-builder.html. This enables creating queries like this:
return new JpaQueryBuilder().buildQuery(em,
new Object[] {
"select c from Car c where c.name is not null",
new JQBParam("name", name, " and c.name = :name"),
new JQBParam("type", type, " and c.type = :type")
}
)