gpt4 book ai didi

grails - Grails 2.4.3中是否禁止将 'applicationContext'作为域名属性名称?

转载 作者:行者123 更新时间:2023-12-02 14:42:48 25 4
gpt4 key购买 nike

从Grails 2.2.4迁移到2.4.3后,具有属性applicationContext的域类在标准查询中使用该属性时会引发异常。

class WebResource {
String applicationContext
}

class ResourceService {
public WebResource getResourceByContext(String ctx) {
WebResource.withCriteria() {
eq('applicationContext', ctx)
}
}
}

调用getResourceByContext()会引发异常:
    org.hibernate.QueryException: could not resolve property: applicationContext of: org.mydomain.WebResource at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83)        at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77)        at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1995)        at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:61)        at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1970)        at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:518)        at org.hibernate.loader.criteria.CriteriaQueryTranslator.findColumns(CriteriaQueryTranslator.java:534)        at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:82)        at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:417)        at org.hibernate.loader.criteria.CriteriaJoinWalker.(CriteriaJoinWalker.java:123)        at org.hibernate.loader.criteria.CriteriaJoinWalker.(CriteriaJoinWalker.java:92)        at org.hibernate.loader.criteria.CriteriaLoader.(CriteriaLoader.java:97)        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1663)        at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)        at org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder.invokeMethod(AbstractHibernateCriteriaBuilder.java:1639)        at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:907)        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:884)        at org.grails.datastore.gorm.GormStaticApi$_withCriteria_closure11.doCall(GormStaticApi.groovy:304)        at sun.reflect.GeneratedMethodAccessor254.invoke(Unknown Source)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)        at groovy.lang.Closure.call(Closure.java:423)        at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:51)        at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:81)        at com.sun.proxy.$Proxy29.doInSession(Unknown Source)        at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:302)        at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37)        at org.grails.datastore.gorm.GormStaticApi.withCriteria(GormStaticApi.groovy:303)        at org.mydomain.WebResource.withCriteria(WebResource.groovy)

Is having domain properties with the name 'applicationContext' not allowed in Grails 2.4.3? I could not find a reference to this scenario being forbidden in the Grails release notes, upgrade guides, or JIRA. I have worked around this issue by renaming the field and changing GORM references to the new name:

class WebResource {
String appContext
appContext column: 'APPLICATION_CONTEXT'
public String getApplicationContext() {
return appContext
}

public void setApplicationContext(String c) {
appContext = c
}
}

最佳答案

给定名称与Spring ApplicationContext的冲突,我怀疑您已经找到了最佳答案-将属性命名为其他名称,然后使用mapping定义来设置数据库列名称。我建议您不要添加getter / setter对,而只需在代码中直接使用属性名称appContext,因为Grails核心或插件中有很多地方假设(相当合理地)假设一个名为applicationContext是Spring对象,而不是其他任何对象。

除非必须这样做,否则请不要违反约定。

关于grails - Grails 2.4.3中是否禁止将 'applicationContext'作为域名属性名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25650706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com