【问题标题】:Grails - MySQL query result with a zero index causing GORM runtime exceptionGrails - 零索引的 MySQL 查询结果导致 GORM 运行时异常
【发布时间】:2012-05-25 20:20:24
【问题描述】:

我正在使用来自开源应用程序 (OSTicket) 的现有数据库。有两个表(OstStaff 和 OstTicket,其中工作人员有很多门票)。但是,最大的问题是当票证尚未分配给 OstStaff 时,OSTicket 将默认值零分配给 OstTicket.staff_id。

当您搜索票证并且GORM认为存在索引等于0的员工时出现问题。我什至无法检查null,只是不断收到此错误:

No row with the given identifier exists: [com.facilities.model.OstFacStaff#0]. 
Stacktrace follows:
Message: No row with the given identifier exists: [com.facilities.model.OstFacStaff#0]

有什么建议可以解决这个问题吗?谢谢。

【问题讨论】:

    标签: mysql grails grails-orm


    【解决方案1】:

    通过仅获取 id 而不是记录,然后删除零索引来解决此问题。

    def ticketCriteria = OstFacTicket.createCriteria()
    def staffIdsWithTickets = ticketCriteria.list {
        projections {
            distinct("staff.id")  // **INSTEAD of returning staff, get the id**
        }
        between("created", start, end)
    }
    
    def zeroIndex = staffIdsWithTickets.indexOf(0)
    if (zeroIndex >= 0) {
        staffIdsWithTickets.remove(zeroIndex)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多