【发布时间】:2014-12-09 01:16:05
【问题描述】:
决定添加一个小日志,主要记录代码、请求 ip 和日期戳。
这是领域类
class Requestlog {
String countryiso
Date requestdate
String requestaddr
static constraints = {
}
}
以及创建记录的代码
def reqip = request.remoteAddr
def reqdate = new Date()
def reqrec = new Requestlog(countryiso: countryiso, requestaddr: reqip, requestdate: reqdate )
reqrec.save(flush:true,failOnError:true)
但是如果来自同一 IP 的相同代码被请求两次(在不同时间)
Duplicate entry 'GL' for key 'UK_3noxnln23h2w0wtormncmk2a1'. Stacktrace follows:
Message: Duplicate entry 'GL' for key 'UK_3noxnln23h2w0wtormncmk2a1'
Line | Method
问题是,我没有将任何列设置为唯一的。并且查看数据库模式,除了 id 列自动递增之外没有其他限制。
【问题讨论】: