【问题标题】:Grails DetachedCriteria using 'where' throw SyntaxErrorExceptionGrails DetachedCriteria 使用 'where' 抛出 SyntaxErrorException
【发布时间】:2014-06-24 10:04:35
【问题描述】:

我正在尝试进行下一个选择:


ArrayList<Personal> personalAuxList = new ArrayList<Personal>()
def campaigns = Campaign.findAllByEntidad(entidadInstance,[sort: "fechaFin", order: "desc"])
//Here a declare a DetachedCriteria using where method of domain class
def notificacionesQuery = Notificacion.where {
    orden.linea.propuesta.campaign in campaigns
}
//For each persona from a search result done before     
for(Personal person : result.results){
    if(!personalAuxList.contains(person)){
        //I add a condition to query creating new one
        def notisOfPersonalQuery = notificacionesQuery.where {
            personal == person
        }
        //Fail in this line when i list the result
        def notificaciones = notisOfPersonalQuery.list()
        notificaciones = notificaciones.sort{it.orden.linea.fin}.reverse()
        notisOfPersonal.put(person.id, notificaciones.empty ? null : notificaciones.first())
        personalAuxList.add(person)
    }
}

这在本地工作正常,但是当我上传战争时,开始在服务器中失败:


类: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

消息:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 ') 和 this_.personal_id=6616' 附近使用正确的语法


追踪:


Line | Method

->>  411 | handleNewInstance    in com.mysql.jdbc.Util

|    386 | getInstance          in     ''
|   1052 | createSQLException . in com.mysql.jdbc.SQLError
|   4098 | checkErrorPacket     in com.mysql.jdbc.MysqlIO
|   4030 | checkErrorPacket . . in     ''
|   2490 | sendCommand          in     ''
|   2651 | sqlQueryDirect . . . in     ''
|   2677 | execSQL              in com.mysql.jdbc.ConnectionImpl
|   2134 | executeInternal . .  in com.mysql.jdbc.PreparedStatement
|   2300 | executeQuery         in     ''
|     97 | executeQuery . . . . in org.apache.commons.dbcp.DelegatingPreparedStatement
|    671 | doCall               in grails.gorm.DetachedCriteria$_list_closure2
|    934 | doCall . . . . . . . in grails.gorm.DetachedCriteria$_withPopulatedQuery_closure9
|    669 | doCall               in org.grails.datastore.gorm.GormStaticApi$_withDatastoreSession_closure20
|    302 | execute . . . . . .  in org.grails.datastore.mapping.core.DatastoreUtils
|     34 | execute              in org.grails.datastore.gorm.AbstractDatastoreApi
|    668 | withDatastoreSession in org.grails.datastore.gorm.GormStaticApi
|    916 | withPopulatedQuery   in grails.gorm.DetachedCriteria
|    667 | list . . . . . . . . in     ''
|    666 | list                 in     ''
|    301 | search . . . . . . . in com.publidirecta.PersonalController
^    722 | run                  in java.lang.Thread

【问题讨论】:

    标签: mysql hibernate grails


    【解决方案1】:

    我终于解决了,在本地我在 DDBB 中有活动,但在真实服务器上没有,所以如果没有活动,我更改代码以添加条件:


    ArrayList<Personal> personalAuxList = new ArrayList<Personal>()
    def campaigns = Campaign.findAllByEntidad(entidadInstance,[sort: "fechaFin", order: "desc"])
    if (campaigns != null && campaigns.size() > 0) {
        def notificacionesQuery = Notificacion.where {
            orden.linea.propuesta.campaign in campaigns
        } 
        for(Personal person : result.results){
            if(!personalAuxList.contains(person)){
                def notisOfPersonalQuery = notificacionesQuery.where {
                    personal == person
                }
                def notificaciones = notisOfPersonalQuery.list()
                notificaciones = notificaciones.sort{it.orden.linea.fin}.reverse()
                notisOfPersonal.put(person.id, notificaciones.empty ? null : notificaciones.first())
                personalAuxList.add(person)
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多