這很奇怪。Grails GORM映射嘗試訪問無處存在的字段「class」
class Service implements Serializable{
Integer id
String serviceName
String description
SortedSet serviceRequirements
static hasMany = [ serviceRequirements : ServiceRequirement]
static mapping =
{
table 'service'
columns {
id column:'serviceId'
}
}}
產生的休眠的SQL訪問時是serviceInstance.serviceRequirements:
servicereq0_.serviceId as serviceId1_,
servicereq0_.serviceRequirementId as serviceR1_1_,
servicereq0_.serviceRequirementId as serviceR1_9_0_,
servicereq0_.version as version9_0_,
servicereq0_.description as descript3_9_0_,
servicereq0_.header as header9_0_,
servicereq0_.isPersonal as isPersonal9_0_,
servicereq0_.requirementKey as requirem6_9_0_,
servicereq0_.required as required9_0_,
servicereq0_.serviceId as serviceId9_0_,
servicereq0_.type as type9_0_,
servicereq0_.weight as weight9_0_,
servicereq0_.oauthAccessTokenUrl as oauthAc12_9_0_,
servicereq0_.oauthAuthorizeAdditionalParameters as oauthAu13_9_0_,
servicereq0_.oauthAuthorizeState as oauthAu14_9_0_,
servicereq0_.oauthAuthorizeUrl as oauthAu15_9_0_,
servicereq0_.oauthClientId as oauthCl16_9_0_,
servicereq0_.oauthClientSecret as oauthCl17_9_0_,
servicereq0_.oauthRequestTokenUrl as oauthRe18_9_0_,
servicereq0_.oauthType as oauthType9_0_,
servicereq0_.class as class9_0_
所有字段是除了最後一個 「類」 OK。它在數據庫或稱爲ServiceRequirement的域類中完全不存在。
你能不能展示ServiceRequirement類的代碼? –
無關 - 您不需要指定'id'字段(即使您想在'mapping'塊中定製它),因爲Grails會爲您自動生成它。你也可以省略表名映射,因爲這就是名字。 –