Gunakan withTransaction
alih-alih withConnection
seperti ini:
private def incrementHitCounter(urlName:String) {
DB.withTransaction { implicit connection =>
SQL("select @hits:=hits from content_url_name where url_name={urlName};").on("urlName" -> urlName).apply()
SQL("update content_url_name set hits = @hits + 1 where url_name={urlName};").on("urlName" -> urlName).executeUpdate()
}
}
Dan mengapa Anda bahkan menggunakan transaksi di sini? Ini juga harus berfungsi:
private def incrementHitCounter(urlName:String) {
DB.withConnection { implicit connection =>
SQL("update content_url_name set hits = (select hits from content_url_name where url_name={urlName}) + 1 where url_name={urlName};").on("urlName" -> urlName).executeUpdate()
}
}