Skip to content

Instantly share code, notes, and snippets.

@julienfantin
Created November 19, 2013 01:14
Show Gist options
  • Select an option

  • Save julienfantin/7538496 to your computer and use it in GitHub Desktop.

Select an option

Save julienfantin/7538496 to your computer and use it in GitHub Desktop.
Proper nesting of jdbc transactions
(do
(jdbc/db-transaction [con db-spec]
(jdbc/insert! con :user {:name "test" :email "test"})
;; the key here is to derive the inner transaction from the outer connection
(jdbc/db-transaction [con2 con]
(jdbc/insert! con2 :user {:name "test2" :email "test2"})
;; now this rolls back both inserts
(jdbc/db-set-rollback-only! con2)))
(println (jdbc/query db-spec ["select * from user"])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment