【发布时间】:2018-03-15 16:08:56
【问题描述】:
我正在尝试创建一个函数,允许用户喜欢/不喜欢我的 Grails 应用程序中的进程。我以前为文章做过,而且效果很好。出于某种原因,当我尝试以同样的方式处理进程时,我得到了这个异常:
Message
Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error evaluating expression [businessProcess?.getLikedCount()] on line [18]: could not prepare statement
Caused by
Column "THIS_.LIKED" does not exist Column "THIS_.LIKED" not found; SQL statement: select count(*) as y0_ from business_process_like this_ where this_.liked=? limit ? [42122-191]
这是BusinessProcessLike 代码的域类:
class BusinessProcessLike {
BusinessProcess businessProcess
ServiceUser serviceUser
boolean liked;
static constraints = {
businessProcess nullable: false
serviceUser nullable: false
liked nullable: false
}
}
相比之下,ArticleLike 看起来像这样:
class ArticleLike {
Article article
ServiceUser serviceUser
boolean liked;
static constraints = {
article nullable: false
serviceUser nullable: false
}
}
这可能是什么原因?我已经检查了一些关于同样问题的帖子,但事实总是正在使用的单词被数据库保留,但事实并非如此。
另外,这是导致异常的方法:
@Transactional
def businessProcessLikeAction(){
ServiceUser user = springSecurityService.currentUser
BusinessProcess businessProcess = BusinessProcess.findById(params.getIdentifier())
//line below throws the exception
BusinessProcessLike processLike = BusinessProcessLike.findByBusinessProcessAndServiceUser(businessProcess, user);
if(!processLike){
processLike = new BusinessProcessLike(businessProcess: businessProcess, serviceUser: user)
}
processLike.liked = Boolean.valueOf(params.status)
processLike.save()
redirect(action: "showBusinessProcessList")
}
【问题讨论】:
标签: database grails controller grails-orm