开发者

Grails GORM mapping tries to access field "class" which exists nowhere

开发者 https://www.devze.com 2023-04-04 18:10 出处:网络
This is pretty strange. class Service implements Serializable{ Integer id String serviceName String description

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:

  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开发者_JAVA百科 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.


A column named class is automatically added to a table when it stores multiple classes. 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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号