Grails get()生成不完整的SQL

时间:2012-11-13 20:21:06

标签: database grails gorm

我正在将应用程序从Grails 1.3.6升级到2.1.1。有点似乎是一个非常奇怪的问题。

我有一张名为SECTION的表。这个电话:

def testSection = Section.get(94725)

在Grails 1.3.6中生成此SQL:

select
    section0_.ID as ID42_0_,
    section0_.concept_tag_uri as concept2_42_0_,
    section0_.INDEX_ID as INDEX3_42_0_,
    section0_.LIVE_IND as LIVE4_42_0_,
    section0_.NAME as NAME42_0_,
    section0_.PARENT_ID as PARENT6_42_0_,
    section0_.ASST_INDEX_ASSET_ID as ASST7_42_0_,
    section0_.ORDER_NO as ORDER8_42_0_,
    section0_.SITE_ID as SITE9_42_0_,
    section0_.TYPE_ID as TYPE10_42_0_,

    (SELECT
        uk_sec.id 
    FROM
        section uk_sec,
        site uk_site 
    WHERE
        uk_sec.index_id = section0_.index_id 
        AND uk_sec.site_id = uk_site.siteid 
        AND uk_site.audienceid  = 1) as formula1_0_ 
from
    SECTION section0_ 
where
    section0_.ID=?

但2.1.1中的这个SQL:

select 
    section0_.ID as ID45_0_, 
    section0_.concept_tag_uri as concept2_45_0_, 
    section0_.INDEX_ID as INDEX3_45_0_, 
    section0_.LIVE_IND as LIVE4_45_0_, 
    section0_.NAME as NAME45_0_, 
    section0_.PARENT_ID as PARENT6_45_0_, 
    section0_.ASST_INDEX_ASSET_ID as ASST7_45_0_, 
    section0_.ORDER_NO as ORDER8_45_0_, 
    section0_.SITE_ID as SITE9_45_0_, 

    (SELECT 
        uk_sec.id 
    FROM section uk_sec, 
        site uk_site 
    WHERE uk_sec.index_id = section0_.index_id 
        AND uk_sec.site_id = uk_site.siteid 
        AND uk_site.audienceid  = 1) as formula1_0_ 
from 
    SECTION section0_ where section0_.ID=?

看起来很相似,但2.1.1版本中缺少此部分:

section0_.TYPE_ID as TYPE10_42_0_,

这是班级中的映射:

...
String sectionType
...
static mapping = 
{
    table 'SECTION'
    version false
    id generator:'assigned'

    columns {
                    ...
        sectionType  column: 'TYPE_ID'
                    ...
    }
}

有问题的DB字段是:TYPE_ID CHAR(1)但是由于get()生成了SQL,我假设它与实际的DB模式或列(?)无关。

它是选择字段列表中的最后一个元素这一事实让我觉得它有某种相关性,但我不知道如何改变它,或者如果这样做只是从语句中“删除”另一个字段。 / p>

有人见过这样的事吗?

干杯, spacebot

1 个答案:

答案 0 :(得分:0)

可能有些仓促地认为这可能是一个错误。

Grails2.1.1需要重写的setter的参数类型,它在1.x中更宽容。

public void setType(type) { ... }  // works in 1.3.6, breaks 2.1.1

public void setType(String type) { ... }  // ok in 2.1.1