gpt4 book ai didi

database - Grails get()生成不完整的SQL

转载 作者:行者123 更新时间:2023-12-02 14:54:12 25 4
gpt4 key购买 nike

我正在将应用程序从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),但是由于SQL是由get()生成的,因此假设它与实际的DB模式或column(?)无关。

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

有人看到过这样的东西吗?

干杯,
太空机器人

最佳答案

也许有些草率地认为这可能是一个错误。

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

关于database - Grails get()生成不完整的SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13368117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com