I’m having a problem with this hql in a grails app:
this is the query
def books = Book.findAll("from book where author_id in (${listOfId?.join(',')}) and (owner_id is null or owner_id = ${ownerId}) and status = 'available'")
And this is the error:
org.codehaus.groovy.grails.orm.hibernate.exceptions.GrailsQueryException: Invalid query [from coupon where campaign_id in (7) and (owner_id is null or owner_id = 1112) and status = 'available']
Any idea of why is this an invalid query? I’m looking for a hql validator with more info about what’s the invalid part. No success for now
Thanks in advance
It looks like your HQL query uses table and column names instead of using entities, fields and associations. You haven’t shown your entities, but if they respect the usual conventions, the HQL query should look like
You should also use parameterized queries instead of String concatenation. That makes your code less efficient, and subject to SQL injection attacks or simply escaping problems: