2012-04-27 80 views
0

我有一個像Grails的FindBy *與inteface財產

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 { 

} 

我用嘲笑的對象,用於測試

感謝

+0

您可以添加您的AccountOwner域名類嗎? – Joseph 2012-04-27 19:58:15

+0

包br.com.fisgo.financial; public interface AccountOwner { } 它在AccountOwner.java文件中 – 2012-04-27 20:20:14

回答

0

由於findBy *由GORM和格姆處理不處理,我不認爲這是去上班的接口。你可以讓AccountOwner成爲抽象類嗎?