grails / grails-data-mapping

GORM - Groovy Object Mapping
http://gorm.grails.org/
218 stars 198 forks source link

Data services. JPA-QL in @Query annotation can't recognize property id #1078

Closed kefirfromperm closed 6 years ago

kefirfromperm commented 6 years ago

When I try to use property id in the @Query annotation it fails on compilation.

Task List

Steps to Reproduce

  1. Create a simple domain object

    class Book {
    String title
    
    static constraints = {
    }
    }
  2. Create a data service
    @Service(Book)
    interface BookService {
    @Query("update ${Book book} set ${book.title} = $title where ${book.id} = $id")
    void update(long id, String title)
    }
  3. build
    gradlew build

Expected Behaviour

It is compiled

Actual Behaviour

Is is not compiled and show error

/home/kefir/projects/gorm-bug-sample/grails-app/services/gorm/bug/sample/BookService.groovy: 8: No property [id] existing for domain class [gorm.bug.sample.Book]
 @ line 8, column 67.
   ${book.title} = $title where ${book.id} 

Environment Information

Example Application

https://github.com/kefirfromperm/gorm-bug-sample

zyro23 commented 6 years ago

looks like the problem could be that ServiceTransformation (CompilePhase.SEMANTIC_ANALYSIS) runs before EntityASTTransformation/GormEntityTransformation (CompilePhase.CANONICALIZATION) which inject the id property?

sample compiles for me if i define the id property in Book explicitly (i.e. Long id)

kefirfromperm commented 6 years ago

Yes if you define id it compiles, but this is not i want. :)