gpt4 book ai didi

grails - 使用eachWithIndex引导域

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

另一个让人头疼的问题是:-(请帮助。我只是想在Grails 3项目的引导文件中使用eachWithIndex批量创建域实例。

这是我的域名类(class)...

package ttt_server

class TttPriority {

String name
int order
Date dateCreated

static constraints = {
name blank: false, nullable: false
order blank: false, nullable: false
dateCreated nullable:true, blank:true
}

}

这是我用于批量创建的引导代码...
["Mortal","Major","Critical","Minor","Nice To Have"].eachWithIndex{ name, idx ->
new TttPriority(name: name, order: idx).save(flush:true)
}

我快要把头发拔出来了。

这是错误...

2017-07-31 16:30:41.755 ERROR --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order) values (0, 'Mortal', 0)' at line 1 2017-07-31 16:30:41.817 ERROR --- [ main] o.s.boot.SpringApplication >: Application startup failed

org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute statement; bad SQL grammar [n/a]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order) values (0, 'Mortal', 0)' at line 1 at ...

最佳答案

由于order是保留字,因此您必须在列中使用其他名称。或用反引号括住您的列名


static mapping = {
order column: "order_col"
}

要么
static mapping = {
order column: "`order`"
}

关于grails - 使用eachWithIndex引导域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45420275/

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