Quantcast

Weird behavior with association in find

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Weird behavior with association in find

longwa
I have a domain class like this (this is slimmed down for brevity, of course):

class Contract {
    String name

    static belongsTo = [customer: Customer]

    CustomerHistory findActiveHistoryForCustomer() {

        CustomerHistory.find {
            eq 'customer', customer
        }
    }
}

Calling the findActiveHistoryForCustomer() method fails with:

org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of assignedkey.Customer.id
        at grails.gorm.DetachedCriteria$_get_closure1.doCall(DetachedCriteria.groovy:619)
        at grails.gorm.DetachedCriteria$_withPopulatedQuery_closure9.doCall(DetachedCriteria.groovy:890)
        at org.grails.datastore.gorm.GormStaticApi$_withDatastoreSession_closure18.doCall(GormStaticApi.groovy:555)
        at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:301)
        at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:34)
        at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession(GormStaticApi.groovy:554)
        at grails.gorm.DetachedCriteria.withPopulatedQuery(DetachedCriteria.groovy:873)
        at grails.gorm.DetachedCriteria.get(DetachedCriteria.groovy:618)
        at grails.gorm.DetachedCriteria.find(DetachedCriteria.groovy:602)
        at grails.gorm.DetachedCriteria.find(DetachedCriteria.groovy:601)
        at org.grails.datastore.gorm.GormStaticApi.find(GormStaticApi.groovy:160)
        at assignedkey.Contract.findActiveHistoryForCustomer(Contract.groovy:10)
        at assignedkey.ContractTests.testFind(ContractTests.groovy:27)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
        ... 13 more


If I change the line to read:

eq 'customer', this.customer

Than it works fine.....I assume this may be some kind of proxy or gorm issue but it's still confusing. Anyone else seen behavior like this?

-Aaron
Loading...