使用MYSQL时,Grails标准查询失败并出现synatx错误
当应用程序连接到MYSQL实例时,我有一个查询失败。 使用H2内存数据库时,查询工作正常。 所有其他查询都可以在MYSQL上正常工作。
错误消息:您的SQL语法中有错误; 检查与你的MySQL服务器版本相对应的手册,在第1行'''附近使用正确的语法
控制器操作:
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]
}
当我删除in子句时,该查询针对MYSQL运行。 所以看起来:'in'(“user”,peopleFollowing)正在引发这个问题。 我认为问题在于是MYSQL的保留字。 我尝试过使用反引号,但不断收到语法错误......?
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"
}
}
静态约束= {content(空白:false)}静态映射= {排序dateCreated:“desc”内容类型:“静态约束= {静态约束:PostComment}静态约束=文本“postComments排序:”dateCreated“,顺序:”desc“}}类发布{字符串内容日期dateCreated用户用户static belongsTo = [用户:用户] 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/24339.html
上一篇: Grails criteria query fails with synatx error when using MYSQL
下一篇: Grails with Criteria