【问题标题】:Grails jdbcsqlexception column not found未找到 Grails jdbcsqlexception 列
【发布时间】: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


    【解决方案1】:

    好的,以防万一有人遇到同样的问题 - 它引发异常的原因是在添加新列之前在表中创建了一个对象,因此问题不在代码中,而是在我的行为的错误年表中。每当我试图对给定的表进行操作时,我都会遇到异常,因为 GORM 想要对表中存在的列做一些事情,而不是在之前创建的记录中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      • 2012-02-13
      相关资源
      最近更新 更多