我正在使用clj-record / transaction两个包装两个记录创建。出错,我正在使用clojure.contrib.condition / raise来抛出异常,但这不会回滚任何东西。有什么想法吗?
答案 0 :(得分:1)
我需要使用clojure.contrib.sql / set-rollback-only:
(ns my.namespace.txtest
(:use clojure.contrib.condition)
(:require clj-record.boot
[clj-record.callbacks.built-ins :as cb]
[clj-record.core :as rec]
[clj-record.validation.built-ins :as valid]
[clojure.contrib.sql :as sql]))
(def db {:classname "com.mysql.jdbc.Driver"
:subprotocol "mysql"
:user "mydb"
:password "password"
:subname "//localhost/mydb"})
(defn do-something
(rec/transaction db
(do-something)
(if (some-error-test)
(do
(sql/set-rollback-only)
(raise :type "some-error" :message "Oops")))))