grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

GORM Data Service @Where queries broken after upgrading from Grials 4.0.3 to 4.0.6 and GORM 7.0.4 to 7.0.8

Open jamesdh opened this issue 4 years ago • 2 comments

I tried to upgrade to 4.0.6/7.0.8 since I thought I was experiencing a bug similar to grails/gorm-hibernate5#202, but it appears GORM Data Service Where queries that query on association properties are fundamentally broken.

Task List

  • [x] Steps to reproduce provided
  • [x] Stacktrace (if present) provided
  • [x] Example that reproduces the problem uploaded to Github
  • [x] Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a domain entity that belongsTo a parent entity and also has a simple association with another entity
  2. Create a GORM data service for said domain entity with a custom Where query that restricts based on the belongsTo association as well as a property on it's simple (peer) association

Expected Behaviour

The Where query pass static compilation and works as expected, performing as though it were a regular detached criteria for the given domain class

Actual Behaviour

While the Where query passes static compilation, it fails the actual runtime query. It appears to think the association property is actually on itself.

org.hibernate.QueryException: could not resolve property: isAlive of: com.test.Book
	at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:73)
	at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:67)
	at at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResultViaListCall(AbstractHibernateQuery.java:808)
	at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResult(AbstractHibernateQuery.java:795)
	at grails.gorm.DetachedCriteria.count_closure3(DetachedCriteria.groovy:515)
...

Environment Information

  • Operating System: MacOS 10.15.7
  • GORM Version: 7.0.8.RELEASE
  • Grails Version (if using Grails): 4.0.6
  • JDK Version: 1.8.0.265

Example Application

Library Domain Model Book Domain Model Author Domain Model Book Service BookServiceSpec

jamesdh avatar Dec 29 '20 00:12 jamesdh

I'm witnessing this in Micronaut GORM as well, using grails-database-gorm:7.1.0.M2. It's as if the association is cropped off and it tries to apply the associated property directly to the domain class for which the service belongs to.

jamesdh avatar Feb 15 '21 17:02 jamesdh

It appears the breakage is specific to using the dot notation in the @Where queries. In my local project, converting the query to the equivalent of...

@Where({
    library == library
    author {
        isAlive == true
    }
})
int countBooksWithLivingAuthor(Library library)

...appears to work around this.

jamesdh avatar Feb 15 '21 17:02 jamesdh