Created
November 19, 2013 01:14
-
-
Save julienfantin/7538496 to your computer and use it in GitHub Desktop.
Proper nesting of jdbc transactions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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