更新:
我已经安装了 grails 2.0 我有两个域类ApplicationConfiguration 和 City ,
ApplicationConfiguration 存储默认字段及其值 City 将访问 ApplicationConfiguration 值
class ApplicationConfiguration {
String myDefaultField
String value
static getMyDefaultCity(){
def city_id = ApplicationConfiguration.findByMyDefaultField('city') .id
def cityName = ApplicationConfiguration.get(city_id ).value
}
}
Class City{
def ApplicationConfiguration
String city = ApplicationConfiguration.getMyDefaultCity()
}
基本上我无法从域和服务中访问 GORM 方法,例如 1) executeQuery() 2) find*()
我得到如下错误
... 5 more
Caused by: org.hibernate.InstantiationException: could not instantiate test objectCity
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
... 5 more
Caused by: groovy.lang.MissingMethodException: No signature of method: ApplicationConfiguration.findByMyDefaultFie
ld() is applicable for argument types: (java.lang.String) values: [city]
at ApplicationConfiguration.getMyDefaultCity(ApplicationConfiguration.groovy:63)
at City.<init>(City.groovy:28)
当我ApplicationConfiguration.findByMyDefaultField('city')
在我的控制器中执行此操作时,它工作正常,可以在控制器中访问 GORM 方法
重现错误的测试用例是
1) Create a project using grails project wizard
2) Create two domain classes ApplicationConfiguration(String myDefaultField, String value) and City(String city)
3) Do generate-all for ApplicationConfiguration
4) Now add this "getMyDefaultCity()" with the definition method as shown above
5) Initialize the filed city in City domain class "String city = ApplicationConfiguration.getMyDefaultCity()"
6) Restart the application