简体   繁体   English

Grails GORM映射尝试访问不存在的字段“类”

[英]Grails GORM mapping tries to access field “class” which exists nowhere

This is pretty strange. 这很奇怪。

class Service implements Serializable{

Integer id
String serviceName
String description
SortedSet serviceRequirements

static hasMany = [ serviceRequirements : ServiceRequirement]

static mapping = 
{
    table 'service'

    columns {
        id column:'serviceId'

    }
}}

The resulting hibernate sql when accessing serviceInstance.serviceRequirements is: 访问serviceInstance.serviceRequirements时生成的休眠sql为:

  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_ 

All fields are ok except the last "class". 除了最后一个“类”,所有字段都可以。 It doesn't exist at all in the database or the domain class called ServiceRequirement. 它在数据库或称为ServiceRequirement的域类中根本不存在。

A column named class is automatically added to a table when it stores multiple classes. 当存储多个类时,名为class的列会自动添加到表中。 If the ServiceRequirement class has a subclass that is also a domain class, then the table will need a class column to know what kind of ServiceRequirement it is. 如果ServiceRequirement类具有的子类也是域类,则该表将需要一个class列来知道它是哪种ServiceRequirement Grails is generally smart enough to automatically add the column if dbCreate is set, but you'll need to add it yourself if you're managing your schema manually. 通常,如果设置了dbCreate ,Grails足够聪明,可以自动添加列,但是如果手动管理模式,则需要自己添加列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM