-
Notifications
You must be signed in to change notification settings - Fork 199
Closed
Labels
Description
Running a string based query (findAll, executeQuery, executeUpdate, etc.) with an interpolated class name no longer works in 6.1.x:
void "test findAll with interpolated class name"() {
given:
String className = "Book"
expect:
Book.findAll("from $className") == [] // throws GrailsQueryException
}
Here's the full stacktrace for the failing integration test above:
org.grails.orm.hibernate.exceptions.GrailsQueryException: Invalid query [from :p0] for domain class [hql.gstring.Book]
at org.grails.orm.hibernate.AbstractHibernateGormStaticApi.findAll(AbstractHibernateGormStaticApi.groovy:294)
at org.grails.orm.hibernate.AbstractHibernateGormStaticApi.findAll(AbstractHibernateGormStaticApi.groovy:382)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.findAll(GormEntity.groovy:1247)
at hql.gstring.BookHqlSpec.$tt__$spock_feature_0_1(BookHqlSpec.groovy:20)
at hql.gstring.BookHqlSpec.test findAll with interpolated class name_closure2(BookHqlSpec.groovy)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at grails.transaction.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:70)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:67)
at hql.gstring.BookHqlSpec.test findAll with interpolated class name(BookHqlSpec.groovy)
This used to work prior to 6.1.x, and I believe this issue was introduced while working on #827 . Looks like the current code assumes that any interpolated value is a query parameter.
Example grails 3.2.8/GORM 6.1.1 app that demonstrates the issue. Run the integration tests and you should see the exception.