Grails FindBy* with an inteface property

穿精又带淫゛_ 提交于 2020-01-06 08:46:26

问题


I have a class like

class Account {

    BigDecimal balance = 0
    SortedSet transactions

    AccountOwner owner

    static constraints = {
    }

    static hasMany = [transactions:Transaction]
}

when I try to query the Account like

def account = Account.findByOwner(user)

I get this error

| Failure:  testSave(br.com.fisgo.financial.AccountControllerTests)
|  org.springframework.dao.InvalidDataAccessResourceUsageException: Cannot query [br.com.fisgo.financial.Account] on non-existent property: owner
    at org.grails.datastore.mapping.simple.query.SimpleMapQuery.getValidProperty(SimpleMapQuery.groovy:706)
    at org.grails.datastore.mapping.simple.query.SimpleMapQuery.executeSubQueryInternal(SimpleMapQuery.groovy:644)
    at org.grails.datastore.mapping.simple.query.SimpleMapQuery.executeSubQuery(SimpleMapQuery.groovy:630)
    at org.grails.datastore.mapping.simple.query.SimpleMapQuery.executeQuery(SimpleMapQuery.groovy:63)
    at org.grails.datastore.mapping.query.Query.list(Query.java:486)
    at org.grails.datastore.gorm.finders.AbstractFindByFinder.invokeQuery(AbstractFindByFinder.java:34)
    at org.grails.datastore.gorm.finders.AbstractFindByFinder$1.doInSession(AbstractFindByFinder.java:26)
    at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:301)
    at org.grails.datastore.gorm.finders.AbstractFinder.execute(AbstractFinder.java:40)
    at org.grails.datastore.gorm.finders.AbstractFindByFinder.doInvokeInternal(AbstractFindByFinder.java:24)
    at org.grails.datastore.gorm.finders.DynamicFinder.invoke(DynamicFinder.java:151)
    at org.grails.datastore.gorm.finders.DynamicFinder.invoke(DynamicFinder.java:352)
    at org.grails.datastore.gorm.GormStaticApi.methodMissing(GormStaticApi.groovy:108)
    at br.com.fisgo.financial.AccountController.buyLead(AccountController.groovy:17)
    at br.com.fisgo.financial.AccountControllerTests.testSave(AccountControllerTests.groovy:92)
| Completed 1 unit test, 1 failed in 5414ms
| Tests FAILED  - view reports in target\test-reports

Using this interface

package br.com.fisgo.financial;

public interface AccountOwner {

}

I'm using mocked object for testing

Thanks


回答1:


Since findBy* are handled by GORM and GORM doesn't handle interfaces I don't think it's going to work. Could you make AccountOwner an abstract class?



来源:https://stackoverflow.com/questions/10356922/grails-findby-with-an-inteface-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!