本文介绍了具有接口属性的Grails FindBy *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的课程

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 {

}

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

I'm using mocked object for testing

谢谢

推荐答案

由于findBy *由GORM处理,而GORM不处理接口,因此我认为它不会起作用.您可以将AccountOwner设为抽象类吗?

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?

这篇关于具有接口属性的Grails FindBy *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 08:46