Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #1418

Closed
4 tasks done
jamesdh opened this issue Dec 29, 2020 · 2 comments

Comments

@jamesdh
Copy link

jamesdh commented Dec 29, 2020

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

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • 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 jamesdh changed the title GORM Data Service @Where queries broken after upgrading from 4.0.3 to 4.0.6 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 Dec 29, 2020
@jamesdh
Copy link
Author

jamesdh commented Feb 15, 2021

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
Copy link
Author

jamesdh commented Feb 15, 2021

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 jamesdh closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant