1

我正在将应用程序从 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 模式或列 (?) 无关。

它是选择字段列表中的最后一个元素这一事实让我认为它在某种程度上是相关的,但我不知道如何更改它,或者这样做只会从语句中“删除”另一个字段。

有人见过这样的吗?

干杯,太空机器人

4

1 回答 1

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
于 2012-11-14T12:28:01.330 回答