Grails criteria query fails with synatx error when using MYSQL

I have a query that fails when the application is connected to a MYSQL instance. The query works fine when using the H2 memory database. All other queries work fine with MYSQL.

error Message: 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 ')' at line 1

Controller Action:

def index() {
def currentUser = currentUser()
def peopleFollowing = currentUser.following
def c = Post.createCriteria()
    def postList = c.list  {
       'in' ("user", peopleFollowing)
       'order' "dateCreated", "desc"
    }
[postList:postList, user : currentUser, peopleFollowing:peopleFollowing]
}

The query runs against the MYSQL when I remove the in clause. So it seems that the: 'in' ("user", peopleFollowing) is causing the issue. I think problem is that in is a MYSQL reserved word. I've tried using backticks around in, but keep getting syntax errors...?

class Post {


String content
Date dateCreated
User user


static belongsTo = [user : User]

static hasMany = [postComments: PostComment]

static constraints = {
    content (blank: false)
}

static mapping = {
    sort dateCreated:"desc"
    content type:"text"
    postComments sort:"dateCreated",  order:"desc"
}

}

class Post { String content Date dateCreated User user static belongsTo = [user : User] static hasMany = [postComments: PostComment] static constraints = { content (blank: false) } static mapping = { sort dateCreated:"desc" content type:"text" postComments sort:"dateCreated", order:"desc" } } class Post { String content Date dateCreated User user static belongsTo = [user : User] static hasMany = [postComments: PostComment] static constraints = { content (blank: false) } static mapping = { sort dateCreated:"desc" content type:"text" postComments sort:"dateCreated", order:"desc" } }


我通过这样做来解决问题:

def postList = Post.findAllByUserInList( peopleFollowing )
链接地址: http://www.djcxy.com/p/24340.html

上一篇: grails belongsTo映射到另一个类的属性

下一篇: 使用MYSQL时,Grails标准查询失败并出现synatx错误