简体   繁体   English

找不到Grails jdbcsqlexception列

[英]Grails jdbcsqlexception column not found

I'm trying to create a function that will allow user to like/dislike a process in my Grails app. 我正在尝试创建一个函数,该函数将允许用户喜欢/不喜欢Grails应用程序中的过程。 I've done it before for articles and it's working perfectly. 我之前已经做过文章,并且运行良好。 For some reason, when I try to do it the same way for processes, I got this exception: 出于某种原因,当我尝试以相同的方式对流程执行此操作时,出现了此异常:

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]

This is my domain class for BusinessProcessLike code: 这是我的BusinessProcessLike代码的域类:

class BusinessProcessLike {

    BusinessProcess businessProcess

    ServiceUser serviceUser

    boolean liked;

    static constraints = {
        businessProcess nullable: false
        serviceUser nullable: false
        liked nullable: false
    }
}

In comparison, the ArticleLike looks like this: 相比之下,ArticleLike看起来像这样:

class ArticleLike {

    Article article

    ServiceUser serviceUser

    boolean liked;

    static constraints = {
        article nullable: false
        serviceUser nullable: false
    }

}

What could be the reason for this? 这可能是什么原因? I've already checked some posts about the same problem, but it always was the fact that word being used was reserved by the database, but here is not the case. 我已经检查了有关同一问题的一些帖子,但事实总是这样,事实是所使用的单词已由数据库保留,但事实并非如此。

Also, this is the method that causes the exception: 同样,这是导致异常的方法:

  @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")
    }

OK, just in case someone had the same problem - the reason why it threw the exception was the fact that there's been one object in the table created prior to adding the new column, so the problem was not within the code, but within the wrong chronology of my actions. 好的,以防万一有人遇到相同的问题-引发异常的原因是在添加新列之前在表中创建了一个对象,因此问题不在代码内,而是在错误内我的行动的时间顺序。 Anytime I tried to operate on the given table I had the exception, because GORM wanted to do something with the column that existed in the table, but not in the previously created record. 每当我尝试对给定的表进行操作时,都会有例外,因为GORM希望对表中存在的列(而不是先前创建的记录)进行某些操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM