【问题标题】:Grails FindBy* with an inteface property具有接口属性的 Grails FindBy*
【发布时间】:2012-05-08 13:45:10
【问题描述】:

我有一门课

class Account {

    BigDecimal balance = 0
    SortedSet transactions

    AccountOwner owner

    static constraints = {
    }

    static hasMany = [transactions:Transaction]
}

当我尝试像

一样查询帐户时
def account = Account.findByOwner(user)

我收到此错误

| 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

使用这个界面

package br.com.fisgo.financial;

public interface AccountOwner {

}

我正在使用模拟对象进行测试

谢谢

【问题讨论】:

  • 你能添加你的 AccountOwner 域类吗?
  • 包 br.com.fisgo.financial;公共接口 AccountOwner { } 它在 AccountOwner.java 文件中

标签: grails grails-orm findby


【解决方案1】:

由于 findBy* 由 GORM 处理,而 GORM 不处理接口,我认为它不会起作用。你能让 AccountOwner 成为一个抽象类吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-01
    • 2021-01-29
    • 1970-01-01
    • 1970-01-01
    • 2010-09-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    相关资源
    最近更新 更多