{"id":8370,"date":"2022-11-09T16:02:24","date_gmt":"2022-11-09T08:02:24","guid":{"rendered":"http:\/\/123.57.164.21\/?p=8370"},"modified":"2022-11-09T16:02:54","modified_gmt":"2022-11-09T08:02:54","slug":"springboot-%e4%b8%ad-transactional-%e6%b3%a8%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=8370","title":{"rendered":"SpringBoot \u4e2d @Transactional \u6ce8\u89e3"},"content":{"rendered":"\n<p><strong>\u4e00\u3001\u57fa\u672c\u4ecb\u7ecd<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4e8b\u52a1\u7ba1\u7406\u662f\u5e94\u7528\u7cfb\u7edf\u5f00\u53d1\u4e2d\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u90e8\u5206\u3002Spring \u4e3a\u4e8b\u52a1\u7ba1\u7406\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u652f\u6301\u3002Spring \u4e8b\u52a1\u7ba1\u7406\u5206\u4e3a\u7f16\u7a0b\u5f0f\u548c\u58f0\u660e\u5f0f\u7684\u4e24\u79cd\u65b9\u5f0f\u3002\u672c\u7bc7\u53ea\u8bf4\u660e\u58f0\u660e\u5f0f\u6ce8\u89e3\u3002<\/p>\n\n\n\n<p>1\u3001\u5728 spring \u9879\u76ee\u4e2d, @Transactional \u6ce8\u89e3\u9ed8\u8ba4\u4f1a\u56de\u6eda\u8fd0\u884c\u65f6\u5f02\u5e38\u53ca\u5176\u5b50\u7c7b\uff0c\u5176\u5b83\u8303\u56f4\u4e4b\u5916\u7684\u5f02\u5e38 Spring \u4e0d\u4f1a\u5e2e\u6211\u4eec\u53bb\u56de\u6eda\u6570\u636e\uff08\u5982\u679c\u4e5f\u60f3\u8981\u56de\u6eda\uff0c\u5728\u65b9\u6cd5\u6216\u8005\u7c7b\u52a0\u4e0a@Transactional(rollbackFor = Exception.class) \u5373\u53ef\uff09\u3002\u5f02\u5e38\u7ee7\u627f\u4f53\u7cfb\u5982\u4e0b\u56fe<br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113-865x1024.png\" alt=\"\" class=\"wp-image-8371\" width=\"410\" height=\"485\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113-865x1024.png 865w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113-253x300.png 253w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113-768x909.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113-830x982.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113-230x272.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113-350x414.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113-480x568.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-113.png 980w\" sizes=\"(max-width: 410px) 100vw, 410px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114-1024x255.png\" alt=\"\" class=\"wp-image-8372\" width=\"677\" height=\"168\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114-1024x255.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114-300x75.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114-768x191.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114-830x207.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114-230x57.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114-350x87.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114-480x119.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-114.png 1318w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/figure><\/div>\n\n\n\n<p><strong>2\u3001@Transactional \u6ce8\u89e3\u53ea\u80fd\u5e94\u7528\u5230 public \u65b9\u6cd5\u6216\u8005\u7c7b\u4e0a\u624d\u6709\u6548<\/strong><\/p>\n\n\n\n<p><strong>3\u3001\u4ec0\u4e48\u662f\u4e8b\u52a1<\/strong><\/p>\n\n\n\n<p>\u4e8b\u52a1\uff1a\u662f\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u6700\u5c0f\u5de5\u4f5c\u5355\u5143\uff0c\u662f\u4f5c\u4e3a\u5355\u4e2a\u903b\u8f91\u5de5\u4f5c\u5355\u5143\u6267\u884c\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\uff1b\u8fd9\u4e9b\u64cd\u4f5c\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u4e00\u8d77\u5411\u7cfb\u7edf\u63d0\u4ea4\uff0c\u8981\u4e48\u90fd\u6267\u884c\u3001\u8981\u4e48\u90fd\u4e0d\u6267\u884c\uff1b\u4e8b\u52a1\u662f\u4e00\u7ec4\u4e0d\u53ef\u518d\u5206\u5272\u7684\u64cd\u4f5c\u96c6\u5408\uff08\u5de5\u4f5c\u903b\u8f91\u5355\u5143\uff09\u3002<\/p>\n\n\n\n<p>\u4e8b\u52a1\u7684\u56db\u5927\u7279\u6027\uff1a<\/p>\n\n\n\n<ul><li>\u539f\u5b50\u6027\uff08atomicity\uff09\uff1a\u5f3a\u8c03\u4e8b\u52a1\u7684\u4e0d\u53ef\u5206\u5272. \u4e8b\u52a1\u662f\u6570\u636e\u5e93\u7684\u903b\u8f91\u5de5\u4f5c\u5355\u4f4d\uff0c\u4e8b\u52a1\u4e2d\u5305\u542b\u7684\u5404\u64cd\u4f5c\u8981\u4e48\u90fd\u505a\uff0c\u8981\u4e48\u90fd\u4e0d\u505a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">A,B\u4e3a\u4e00\u4e2a\u4e8b\u52a1\u4e2d\u5bf9\u6570\u636e\u5e93\u7684\u4e24\u4e2a\u6267\u884c\u64cd\u4f5c\uff0cB\u6267\u884c\u5931\u8d25\uff0c\u6839\u636e\u4e8b\u52a1\u539f\u5b50\u6027\uff0cA\u4f1a\u56de\u6eda<\/pre>\n\n\n\n<ul><li>\u4e00\u81f4\u6027 \uff08consistency\uff09:\u4e8b\u52a1\u7684\u6267\u884c\u7684\u524d\u540e\u6570\u636e\u7684\u5b8c\u6574\u6027\u4fdd\u6301\u4e00\u81f4. \u4e8b\u52a1\u6267\u884c\u7684\u7ed3\u679c\u5fc5\u987b\u662f\u4f7f\u6570\u636e\u5e93\u4ece\u4e00\u4e2a\u4e00\u81f4\u6027\u72b6\u6001\u53d8\u5230\u53e6\u4e00\u4e2a\u4e00\u81f4\u6027\u72b6\u6001\u3002\u56e0\u6b64\u5f53\u6570\u636e\u5e93\u53ea\u5305\u542b\u6210\u529f\u4e8b\u52a1\u63d0\u4ea4\u7684\u7ed3\u679c\u65f6\uff0c\u5c31\u8bf4\u6570\u636e\u5e93\u5904\u4e8e\u4e00\u81f4\u6027\u72b6\u6001\u3002\u5982\u679c\u6570\u636e\u5e93\u7cfb\u7edf \u8fd0\u884c\u4e2d\u53d1\u751f\u6545\u969c\uff0c\u6709\u4e9b\u4e8b\u52a1\u5c1a\u672a\u5b8c\u6210\u5c31\u88ab\u8feb\u4e2d\u65ad\uff0c\u8fd9\u4e9b\u672a\u5b8c\u6210\u4e8b\u52a1\u5bf9\u6570\u636e\u5e93\u6240\u505a\u7684\u4fee\u6539\u6709\u4e00\u90e8\u5206\u5df2\u5199\u5165\u7269\u7406\u6570\u636e\u5e93\uff0c\u8fd9\u65f6\u6570\u636e\u5e93\u5c31\u5904\u4e8e\u4e00\u79cd\u4e0d\u6b63\u786e\u7684\u72b6\u6001\uff0c\u6216\u8005\u8bf4\u662f\u4e0d\u4e00\u81f4\u7684\u72b6\u6001\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">\u7532\uff0810\u5143\uff09\u7ed9\u4e59\uff0810\u5143\uff09\u8f6c10\u5757\u94b1\uff0c\u53ea\u4f1a\u51fa\u73b0\u75320\uff0c\u4e5920\u548c\u753210\u548c\u4e5910\u4e24\u79cd\u60c5\u51b5\n<\/pre>\n\n\n\n<ul><li>\u9694\u79bb\u6027 \uff08isolation\uff09:\u4e00\u4e2a\u4e8b\u52a1\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d,\u4e0d\u5e94\u8be5\u53d7\u5230\u5176\u4ed6\u4e8b\u52a1\u7684\u5e72\u6270 \u4e00\u4e2a\u4e8b\u52a1\u7684\u6267\u884c\u4e0d\u80fd\u5176\u5b83\u4e8b\u52a1\u5e72\u6270\u3002\u5373\u4e00\u4e2a\u4e8b\u52a1\u5185\u90e8\u7684\u64cd\u4f5c\u53ca\u4f7f\u7528\u7684\u6570\u636e\u5bf9\u5176\u5b83\u5e76\u53d1\u4e8b\u52a1\u662f\u9694\u79bb\u7684\uff0c\u5e76\u53d1\u6267\u884c\u7684\u5404\u4e2a\u4e8b\u52a1\u4e4b\u95f4\u4e0d\u80fd\u4e92\u76f8\u5e72\u6270\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">A\u548cB\u4e24\u4e2a\u4e8b\u52a1\u4e92\u4e0d\u5e72\u6270<\/pre>\n\n\n\n<ul><li>\u6301\u4e45\u6027 \uff08durability\uff09 :\u4e8b\u52a1\u4e00\u65e6\u7ed3\u675f,\u6570\u636e\u5c31\u6301\u4e45\u5230\u6570\u636e\u5e93 \u4e5f\u79f0\u6c38\u4e45\u6027\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">\u6307\u4e00\u4e2a\u4e8b\u52a1\u4e00\u65e6\u63d0\u4ea4\uff0c\u5b83\u5bf9\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u7684\u6539\u53d8\u5c31\u5e94\u8be5\u662f\u6c38\u4e45\u6027\u7684\u3002\u63a5\u4e0b\u6765\u7684\u5176\u5b83\u64cd\u4f5c\u6216\u6545\u969c\u4e0d\u5e94\u8be5\u5bf9\u5176\u6267\u884c\u7ed3\u679c\u6709\u4efb\u4f55\u5f71\u54cd\u3002<\/pre>\n\n\n\n<p><strong>\u4e8c\u3001\u7b80\u5355\u7684\u4f7f\u7528\u65b9\u6cd5<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u53ea\u9700\u5728\u65b9\u6cd5\u52a0\u4e0a @Transactional \u6ce8\u89e3\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>\u5982\u4e0b\u6709\u4e00\u4e2a\u4fdd\u5b58\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u52a0\u5165 @transactional \u6ce8\u89e3\uff0c\u629b\u51fa\u5f02\u5e38\u4e4b\u540e\uff0c\u4e8b\u52a1\u4f1a\u81ea\u52a8\u56de\u6eda\uff0c\u6570\u636e\u4e0d\u4f1a\u63d2\u5165\u5230\u6570\u636e\u5e93\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    @Override\n    @Transactional\n    public String save(ProductModuleConfig productModuleConfig){\n        productModuleConfigDao.insert(productModuleConfig);\n        if (true) {\n            throw new RuntimeException(\"save\u65b9\u6cd5\u8fd0\u884c\u65f6\u5f02\u5e38\");\n        }\n        return \"\u6210\u529f\";\n    }<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115-1024x308.png\" alt=\"\" class=\"wp-image-8374\" width=\"579\" height=\"173\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115-1024x308.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115-300x90.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115-768x231.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115-830x250.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115-230x69.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115-350x105.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115-480x144.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-115.png 1422w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u4ece\u63a7\u5236\u53f0\u65e5\u5fd7\u53ef\u4ee5\u770b\u51fa\u8fd9\u4e9b\u4fe1\u606f\uff1a<\/p>\n\n\n\n<p>\u8be5\u4e8b\u52a1\u6ca1\u6709\u63d0\u4ea4 commit\uff0c\u56e0\u4e3a\u9047\u5230 RuntimeException \u5f02\u5e38\u8be5\u4e8b\u52a1\u8fdb\u884c\u4e86\u56de\u6eda\uff0c\u6570\u636e\u5e93\u4e2d\u4e5f\u6ca1\u6709\u8be5\u6761\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u518d\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)\n    @Override\n    public String save(ProductModuleConfig productModuleConfig){\n        productModuleConfigDao.insert(productModuleConfig);\n        try {\n            String a = null;\n            boolean equals = a.equals(\"2\");\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        return \"\u6210\u529f\";\n    }<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-116.png\" alt=\"\" class=\"wp-image-8375\" width=\"470\" height=\"186\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-116.png 984w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-116-300x120.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-116-768x306.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-116-830x331.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-116-230x92.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-116-350x139.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-116-480x191.png 480w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u4e09\u3001@Transactional \u6ce8\u89e3\u7684\u5c5e\u6027\u4ecb\u7ecd<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>1\u3001\u4e8b\u52a1\u7684\u4f20\u64ad\u7c7b\u578b\uff08propagation \u5c5e\u6027\u9ed8\u8ba4\u503c\u4e3a Propagation.REQUIRED\uff09<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117-1024x443.png\" alt=\"\" class=\"wp-image-8376\" width=\"567\" height=\"245\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117-1024x443.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117-300x130.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117-768x332.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117-830x359.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117-230x100.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117-350x151.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117-480x208.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-117.png 1428w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><\/figure><\/div>\n\n\n\n<p>&nbsp;2\u3001\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\uff08\u6ce8\uff1a<strong>\u221a \u4e3a\u4f1a\u53d1\u751f\uff0c\u00d7\u4e3a\u4e0d\u4f1a\u53d1\u751f&nbsp; \u9ed8\u8ba4\u503c\u4e3a Isolation.DEFAULT<\/strong>\uff09<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118-1024x468.png\" alt=\"\" class=\"wp-image-8377\" width=\"570\" height=\"260\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118-1024x468.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118-300x137.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118-768x351.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118-830x379.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118-230x105.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118-350x160.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118-480x219.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-118.png 1432w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/figure><\/div>\n\n\n\n<ul><li>\u810f\u8bfb\uff1a\u6307\u5f53\u4e00\u4e2a\u4e8b\u52a1\u6b63\u5728\u8bbf\u95ee\u6570\u636e\uff0c\u5e76\u4e14\u5bf9\u6570\u636e\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u800c\u8fd9\u79cd\u4fee\u6539\u8fd8\u6ca1\u6709\u63d0\u4ea4\u5230\u6570\u636e\u5e93\u4e2d\uff0c\u8fd9\u65f6\uff0c\u53e6\u5916\u4e00\u4e2a\u4e8b\u52a1\u4e5f\u8bbf\u95ee\u8fd9\u4e2a\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528\u4e86\u8fd9\u4e2a\u6570\u636e<\/li><li>\u53ef\u91cd\u590d\u8bfb\uff1a\u6307\u5728\u4e8b\u52a11\u5185\uff0c\u8bfb\u53d6\u4e86\u4e00\u4e2a\u6570\u636e\uff0c\u4e8b\u52a11\u8fd8\u6ca1\u6709\u7ed3\u675f\u65f6\uff0c\u4e8b\u52a12\u4e5f\u8bbf\u95ee\u4e86\u8fd9\u4e2a\u6570\u636e\uff0c\u4fee\u6539\u4e86\u8fd9\u4e2a\u6570\u636e\uff0c\u5e76\u63d0\u4ea4\u3002\u7d27\u63a5\u7740\uff0c\u4e8b\u52a11\u53c8\u8bfb\u8fd9\u4e2a\u6570\u636e\u3002\u7531\u4e8e\u4e8b\u52a12\u7684\u4fee\u6539\uff0c\u90a3\u4e48\u4e8b\u52a11\u4e24\u6b21\u8bfb\u5230\u7684\u6570\u636e\u53ef\u80fd\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u56e0\u6b64\u79f0\u4e3a\u662f\u4e0d\u53ef\u91cd\u590d\u8bfb\u3002<\/li><li>\u5e7b\u8bfb\uff1a\u6307\u7684\u662f\u5f53\u67d0\u4e2a\u4e8b\u52a1\u5728\u8bfb\u53d6\u67d0\u4e2a\u8303\u56f4\u5185\u7684\u8bb0\u5f55\u65f6\uff0c\u53e6\u5916\u4e00\u4e2a\u4e8b\u52a1\u53c8\u5728\u8be5\u8303\u56f4\u5185\u63d2\u5165\u4e86\u65b0\u7684\u8bb0\u5f55\uff0c\u5f53\u4e4b\u524d\u7684\u4e8b\u52a1\u518d\u6b21\u8bfb\u53d6\u8be5\u8303\u56f4\u7684\u8bb0\u5f55\u65f6\uff0c\u4f1a\u4ea7\u751f\u5e7b\u884c\u3002InnoDB \u5b58\u50a8\u5f15\u64ce\u901a\u8fc7\u591a\u7248\u672c\u5e76\u53d1\u63a7\u5236\uff08MVCC\uff09\u89e3\u51b3\u4e86\u5e7b\u8bfb\u7684\u95ee\u9898\u3002\u5e7b\u8bfb\u548c\u4e0d\u53ef\u91cd\u590d\u8bfb\u7684\u533a\u522b\u662f\uff0c\u524d\u8005\u662f\u4e00\u4e2a\u8303\u56f4\uff0c\u540e\u8005\u662f\u672c\u8eab<br><\/li><\/ul>\n\n\n\n<p><strong>&nbsp;\u56db\u3001@Transactional \u6ce8\u89e3\u7684\u4e00\u4e9b\u4ee3\u7801 demo<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u6bd4\u5982\u5982\u4e0b\u4ee3\u7801\uff0csave \u65b9\u6cd5\u9996\u5148\u8c03\u7528\u4e86 method1 \u65b9\u6cd5\uff0c\u7136\u540e save \u65b9\u6cd5\u629b\u51fa\u4e86\u5f02\u5e38\uff0c\u5c31\u4f1a\u5bfc\u81f4\u4e8b\u52a1\u56de\u6eda\uff0c\u5982\u4e0b\u4e24\u6761\u6570\u636e\u90fd\u4e0d\u4f1a\u63d2\u5165\u6570\u636e\u5e93\u3002<strong>\u53ef\u4ece\u63a7\u5236\u53f0\u65e5\u5fd7\u4fe1\u606f\u53ef\u4ee5\u770b\u51fa\uff0c\u6ca1\u6709\u63d0\u4ea4\uff08commit\uff09\u4e8b\u52a1\uff0c\u76f4\u63a5\u56de\u6eda\u6389\u4e86\u3002<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    @Override\n    @Transactional(propagation = Propagation.REQUIRED)\n    public String save(ProductModuleConfig productModuleConfig){\n        method1();\n        productModuleConfigDao.insert(productModuleConfig);\n        if (true) {\n            throw new RuntimeException(\"save\u65b9\u6cd5\u8fd0\u884c\u65f6\u5f02\u5e38\");\n        }\n        return \"\u6210\u529f\";\n    }\n \n    public void method1() {\n        ProductModuleConfig productModuleConfig = new ProductModuleConfig();\n        productModuleConfig.setId(UUID.randomUUID().toString());\n        productModuleConfig.setName(\"\u54c8\u54c8\u54c8\u54c82\");\n        productModuleConfigDao.insert(productModuleConfig);\n    }<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119-1024x357.png\" alt=\"\" class=\"wp-image-8378\" width=\"675\" height=\"234\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119-1024x357.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119-300x104.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119-768x267.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119-830x289.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119-230x80.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119-350x122.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119-480x167.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-119.png 1436w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/figure><\/div>\n\n\n\n<p>\u73b0\u5728\u6709\u5982\u4e0b\u9700\u6c42\uff0c\u5c31\u7b97 save \u65b9\u6cd5\u7684\u540e\u9762\u629b\u5f02\u5e38\u4e86\uff0c\u4e5f\u4e0d\u80fd\u5f71\u54cd method1 \u65b9\u6cd5\u7684\u6570\u636e\u63d2\u5165\u3002\u6216\u8bb8\u5f88\u591a\u4eba\u7684\u60f3\u6cd5\u5982\u4e0b\uff0c\u7ed9 method1 \u65b9\u6cd5\u52a0\u5165\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1\uff0c\u8fd9\u6837 method1 \u5c31\u4f1a\u5728\u8fd9\u4e2a\u65b0\u7684\u4e8b\u52a1\u4e2d\u6267\u884c\uff0c\u539f\u6765\u7684\u4e8b\u52a1\u4e0d\u4f1a\u5f71\u54cd\u5230\u65b0\u7684\u4e8b\u52a1\u3002\u6bd4\u5982 method1 \u65b9\u6cd5\u4e0a\u9762\u518d\u52a0\u5165\u6ce8\u89e3 @Transactional \uff0c\u8bbe\u7f6e propagation \u5c5e\u6027\u4e3a Propagation.REQUIRES_NEW\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    @Override\n    @Transactional(propagation = Propagation.REQUIRED)\n    public String save(ProductModuleConfig productModuleConfig){\n        method1();\n        productModuleConfigDao.insert(productModuleConfig);\n        if (true) {\n            throw new RuntimeException(\"save\u65b9\u6cd5\u8fd0\u884c\u65f6\u5f02\u5e38\");\n        }\n        return \"\u6210\u529f\";\n    }\n \n    @Transactional(propagation = Propagation.REQUIRES_NEW)\n    public void method1() {\n        ProductModuleConfig productModuleConfig = new ProductModuleConfig();\n        productModuleConfig.setId(UUID.randomUUID().toString());\n        productModuleConfig.setName(\"\u54c8\u54c8\u54c8\u54c82\");\n        productModuleConfigDao.insert(productModuleConfig);\n    }<\/pre>\n\n\n\n<p>\u8fd0\u884c\u4e4b\u540e\uff0c\u53d1\u73b0\u6570\u636e\u8fd8\u662f\u6ca1\u6709\u63d2\u5165\u6570\u636e\u5e93\u4e2d\u3002\u600e\u4e48\u56de\u4e8b\uff0c\u6211\u4eec\u5148\u770b\u4e00\u4e0b\u63a7\u5236\u53f0\u65e5\u5fd7\u6253\u5370\u4fe1\u606f\u3002\u4ece\u65e5\u5fd7\u5185\u5bb9\u53ef\u4ee5\u770b\u51fa\uff0c<strong>\u5176\u5b9e\u4e24\u4e2a\u65b9\u6cd5\u90fd\u662f\u5904\u4e8e\u540c\u4e00\u4e2a\u4e8b\u52a1\u4e2d\uff0cmethod1 \u65b9\u6cd5\u5e76\u6ca1\u6709\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1<\/strong>\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-120-1024x373.png\" alt=\"\" class=\"wp-image-8380\" width=\"619\" height=\"224\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-120-1024x373.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-120-300x109.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-120-830x302.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-120-230x84.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-120-350x127.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-120-480x175.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-120.png 1428w\" sizes=\"(max-width: 619px) 100vw, 619px\" \/><\/figure><\/div>\n\n\n\n<p>\u5927\u6982\u610f\u601d\uff1a\u5728\u9ed8\u8ba4\u7684\u4ee3\u7406\u6a21\u5f0f\u4e0b\uff0c\u53ea\u6709\u76ee\u6807\u65b9\u6cd5\u7531\u5916\u90e8\u8c03\u7528\uff0c\u624d\u80fd\u88ab Spring \u7684\u4e8b\u52a1\u62e6\u622a\u5668\u62e6\u622a\u3002 \u5728\u540c\u4e00\u4e2a\u7c7b\u4e2d\u7684\u4e24\u4e2a\u65b9\u6cd5\u76f4\u63a5\u8c03\u7528\uff0c\u662f\u4e0d\u4f1a\u88ab Spring \u7684\u4e8b\u52a1\u62e6\u622a\u5668\u62e6\u622a\uff0c\u5c31\u50cf\u4e0a\u9762\u7684 insert \u65b9\u6cd5\u76f4\u63a5\u8c03\u7528\u4e86\u540c\u4e00\u4e2a\u7c7b\u4e2d\u7684 method1 \u65b9\u6cd5\uff0cmethod1 \u65b9\u6cd5\u4e0d\u4f1a\u88ab Spring \u7684\u4e8b\u52a1\u62e6\u622a\u5668\u62e6\u622a\uff0c\u4e5f\u5c31\u662f\u8bf4 method1 \u65b9\u6cd5\u4e0a\u7684\u6ce8\u89e3\u662f\u5931\u6548\u7684\uff0c\u6839\u672c\u6ca1\u8d77\u4f5c\u7528\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u65b0\u5efa\u4e00\u4e2a\u7c7b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Service\npublic class OtherServiceImpl implements OtherService {\n \n    @Resource\n    private ProductModuleConfigDao productModuleConfigDao;\n \n    @Transactional(propagation = Propagation.REQUIRES_NEW)\n    @Override\n    public void method() {\n        ProductModuleConfig productModuleConfig = new ProductModuleConfig();\n        productModuleConfig.setId(UUID.randomUUID().toString());\n        productModuleConfig.setName(\"\u54c8\u54c8\u54c8\u54c83\");\n        productModuleConfigDao.insert(productModuleConfig);\n    }\n \n}<\/pre>\n\n\n\n<p>\u7136\u540e\u5728 save \u65b9\u6cd5\u4e2d\u8c03\u7528 otherService.method1 \u65b9\u6cd5<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Override\n    @Transactional(propagation = Propagation.REQUIRED)\n    public String save(ProductModuleConfig productModuleConfig){\n\/\/        method1();\n        otherService.method1();\n        productModuleConfigDao.insert(productModuleConfig);\n        if (true) {\n            throw new RuntimeException(\"save\u65b9\u6cd5\u8fd0\u884c\u65f6\u5f02\u5e38\");\n        }\n        return \"\u6210\u529f\";\n    }\n<\/pre>\n\n\n\n<p><br>\u8fd9\u4e0b\uff0cotherService.method1 \u65b9\u6cd5\u7684\u6570\u636e\u63d2\u5165\u6210\u529f\uff0c\u4e8b\u52a1\u63d0\u4ea4\u4e86\u3002save \u65b9\u6cd5\u7684\u6570\u636e\u672a\u63d2\u5165\uff0c\u4e8b\u52a1\u56de\u6eda\u4e86\u3002\u7ee7\u7eed\u770b\u4e00\u4e0b\u65e5\u5fd7\u5185\u5bb9\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121-1024x367.png\" alt=\"\" class=\"wp-image-8381\" width=\"557\" height=\"200\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121-1024x367.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121-300x107.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121-768x275.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121-830x297.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121-230x82.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121-350x125.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121-480x172.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-121.png 1446w\" sizes=\"(max-width: 557px) 100vw, 557px\" \/><\/figure><\/div>\n\n\n\n<p>\u4ece\u65e5\u5fd7\u53ef\u4ee5\u770b\u51fa\uff0c\u9996\u5148\u521b\u5efa\u4e86 save \u65b9\u6cd5\u7684\u4e8b\u52a1\uff0c\u7531\u4e8e otherService.method1 \u65b9\u6cd5\u7684 @transactional \u7684 propagation \u5c5e\u6027\u4e3a Propagation.REQUIRES_NEW\uff0c\u6240\u4ee5\u63a5\u7740\u6682\u505c\u4e86 save \u65b9\u6cd5\u7684\u4e8b\u52a1\uff0c\u91cd\u65b0\u521b\u5efa\u4e86 otherService.method1 \u65b9\u6cd5\u7684\u4e8b\u52a1\uff0c\u63a5\u7740 otherService.method1 \u65b9\u6cd5\u7684\u4e8b\u52a1\u63d0\u4ea4\uff0c\u63a5\u7740 save \u65b9\u6cd5\u7684\u4e8b\u52a1\u56de\u6eda\u3002\u8fd9\u5c31\u5370\u8bc1\u4e86\u53ea\u6709\u76ee\u6807\u65b9\u6cd5\u7531\u5916\u90e8\u8c03\u7528\uff0c\u624d\u80fd\u88ab Spring \u7684\u4e8b\u52a1\u62e6\u622a\u5668\u62e6\u622a\u3002<\/p>\n\n\n\n<p><strong>\u8fd8\u6709\u51e0\u4e2a\u793a\u4f8b\u5982\u4e0b\uff08\u6309\u4e0a\u9762\u7684\u4ee3\u7801\u8fdb\u884c\u62d3\u5c55\uff09\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Transactional(propagation = Propagation.REQUIRED)\n    @Override\n    public String save(ProductModuleConfig productModuleConfig){\n\/\/        method1();\n        otherService.method1();\n        productModuleConfigDao.insert(productModuleConfig);\n        if (true) {\n            throw new RuntimeException(\"save\u65b9\u6cd5\u8fd0\u884c\u65f6\u5f02\u5e38\");\n        }\n        return \"\u6210\u529f\";\n    }\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Service\npublic class OtherServiceImpl implements OtherService {\n \n    @Resource\n    private ProductModuleConfigDao productModuleConfigDao;\n \n    @Transactional(propagation = Propagation.REQUIRES_NEW)\n    @Override\n    public void method1() {\n        ProductModuleConfig productModuleConfig = new ProductModuleConfig();\n        productModuleConfig.setId(UUID.randomUUID().toString());\n        productModuleConfig.setName(\"\u54c8\u54c8\u54c8\u54c83\");\n        productModuleConfigDao.insert(productModuleConfig);\n        \/*if (true) {\n            throw new RuntimeException(\"method1\u65b9\u6cd5\u5f02\u5e38\");\n        }*\/\n    }\n \n}\n<\/pre>\n\n\n\n<p>\u7ec4\u5408\u6392\u5217\uff08 <strong>save \u65b9\u6cd5\u4e00\u76f4\u90fd\u6709\u629b\u51fa\u8fd0\u884c\u65f6\u5f02\u5e38<\/strong>\uff09\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122-1024x465.png\" alt=\"\" class=\"wp-image-8382\" width=\"626\" height=\"284\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122-1024x465.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122-300x136.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122-768x349.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122-830x377.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122-230x104.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122-350x159.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122-480x218.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-122.png 1410w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123-1024x454.png\" alt=\"\" class=\"wp-image-8383\" width=\"640\" height=\"283\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123-1024x454.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123-300x133.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123-768x340.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123-830x368.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123-230x102.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123-350x155.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123-480x213.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-123.png 1418w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-124-1024x458.png\" alt=\"\" class=\"wp-image-8384\" width=\"584\" height=\"260\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-124-1024x458.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-124-300x134.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-124-230x103.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-124-350x157.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-124-480x215.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-124.png 1412w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125-1024x463.png\" alt=\"\" class=\"wp-image-8385\" width=\"622\" height=\"280\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125-1024x463.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125-300x136.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125-768x347.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125-830x375.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125-230x104.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125-350x158.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125-480x217.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/\u56fe\u7247-125.png 1412w\" sizes=\"(max-width: 622px) 100vw, 622px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u4e94\u3001@Transactional \u6ce8\u89e3\u5931\u6548\u573a\u666f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>1\u3001@Transactional \u6ce8\u89e3\u5e94\u7528\u5728\u975e public \u4fee\u9970\u7684\u65b9\u6cd5\u4e0a\uff0c\u5bfc\u81f4\u6ce8\u89e3\u5931\u6548<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">protected\u3001private \u4fee\u9970\u7684\u65b9\u6cd5\u4e0a\u4f7f\u7528 @Transactional \u6ce8\u89e3\uff0c\u4e8b\u52a1\u662f\u65e0\u6548<\/pre>\n\n\n\n<p>2\u3001propagation \u8bbe\u7f6e\u9519\u8bef\uff0c\u5bfc\u81f4\u6ce8\u89e3\u5931\u8d25<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">propagation \u5c5e\u6027\u8bbe\u7f6e\u4e3a PROPAGATION_SUPPORTS\u3001PROPAGATION_NOT_SUPPORTED\u3001 PROPAGATION_NEVER \u8fd9\u4e09\u79cd\u7c7b\u522b\u65f6\uff0c@Transactional \u6ce8\u89e3\u5c31\u4e0d\u4f1a\u4ea7\u751f\u6548\u679c\u3002<\/pre>\n\n\n\n<p>3\u3001rollbackFor \u8bbe\u7f6e\u9519\u8bef\uff0c@Transactional \u6ce8\u89e3\u5931\u8d25<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Spring \u9ed8\u8ba4\u56de\u6eda\u4e8b\u52a1\u5206\u522b\u4e3a\u629b\u51fa\u4e86\u672a\u68c0\u67e5 unchecked \u5f02\u5e38\uff08\u7ee7\u627f\u81ea RuntimeException \u7684\u5f02\u5e38\uff09\u548c Error \u4e24\u79cd\u60c5\u51b5\uff0c\u5176\u4ed6\u5f02\u5e38\u4e0d\u4f1a\u56de\u6eda\uff0c\u5e0c\u671b\u629b\u51fa\u5176\u4ed6\u5f02\u5e38 Spring \u4ea6\u80fd\u56de\u6eda\u4e8b\u52a1\uff0c\u9700\u8981\u6307\u5b9a rollbackFor \u5c5e\u6027<\/pre>\n\n\n\n<p>4\u3001\u65b9\u6cd5\u4e4b\u95f4\u7684\u4e92\u76f8\u8c03\u7528\u5bfc\u81f4 @Transactional \u5931\u6548<\/p>\n\n\n\n<p>\u4e24\u4e2a\u65b9\u6cd5\u90fd\u662f\u5904\u4e8e\u540c\u4e00\u4e2a\u4e8b\u52a1\u4e2d\uff0cmethod1 \u65b9\u6cd5\u5e76\u6ca1\u6709\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1\uff0c\u6240\u4ee5 method1 \u65b9\u6cd5\u4e0a\u7684\u6ce8\u89e3\u5931\u6548\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    @Override\n    @Transactional(propagation = Propagation.REQUIRED)\n    public String save(ProductModuleConfig productModuleConfig){\n        method1();\n        productModuleConfigDao.insert(productModuleConfig);\n        if (true) {\n            throw new RuntimeException(\"save\u65b9\u6cd5\u8fd0\u884c\u65f6\u5f02\u5e38\");\n        }\n        return \"\u6210\u529f\";\n    }\n \n    @Transactional(propagation = Propagation.REQUIRES_NEW)\n    public void method1() {\n        ProductModuleConfig productModuleConfig = new ProductModuleConfig();\n        productModuleConfig.setId(UUID.randomUUID().toString());\n        productModuleConfig.setName(\"\u54c8\u54c8\u54c8\u54c82\");\n        productModuleConfigDao.insert(productModuleConfig);\n    }<\/pre>\n\n\n\n<p>5\u3001\u5f02\u5e38\u88ab catch \u6355\u83b7\u5bfc\u81f4 @Transactional \u6ce8\u89e3\u5931\u6548<\/p>\n\n\n\n<p>method2 \u65b9\u6cd5\u662f\u4f1a\u62a5\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u800c save \u65b9\u6cd5\u5bf9\u5176\u8fdb\u884c\u4e86 try catch \u4e86method2 \u65b9\u6cd5\u7684\u5f02\u5e38\uff0c\u90a3 save \u65b9\u6cd5\u7684\u4e8b\u52a1\u5c31\u4e0d\u80fd\u6b63\u5e38\u56de\u6eda\uff0c\u6570\u636e\u8fd8\u662f\u4f1a\u63d2\u5165\u5230\u6570\u636e\u5e93\u4e2d\u7684\uff0c\u6700\u7ec8\u4f1a\u62a5 method2 \u65b9\u6cd5\u7684\u7a7a\u6307\u9488\u5f02\u5e38\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    @Transactional(propagation = Propagation.REQUIRED)\n    @Override\n    public String save(ProductModuleConfig productModuleConfig){\n        try {\n            productModuleConfigDao.insert(productModuleConfig);\n            method2();\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        return \"\u6210\u529f\";\n    }\n \n    public void method2(){\n        String a = null;\n        boolean equals = a.equals(\"2\");\n    }<\/pre>\n\n\n\n<p>6\u3001\u6570\u636e\u5e93\u5f15\u64ce\u4e0d\u652f\u6301\u4e8b\u52a1<\/p>\n\n\n\n<p>\u8fd9\u79cd\u60c5\u51b5\u51fa\u73b0\u7684\u6982\u7387\u5e76\u4e0d\u9ad8\uff0c\u4e8b\u52a1\u80fd\u5426\u751f\u6548\u6570\u636e\u5e93\u5f15\u64ce\u662f\u5426\u652f\u6301\u4e8b\u52a1\u662f\u5173\u952e\u3002\u5e38\u7528\u7684MySQL\u6570\u636e\u5e93\u9ed8\u8ba4\u4f7f\u7528\u652f\u6301\u4e8b\u52a1\u7684innodb\u5f15\u64ce\u3002\u4e00\u65e6\u6570\u636e\u5e93\u5f15\u64ce\u5207\u6362\u6210\u4e0d\u652f\u6301\u4e8b\u52a1\u7684myisam\uff0c\u90a3\u4e8b\u52a1\u5c31\u4ece\u6839\u672c\u4e0a\u5931\u6548\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u57fa\u672c\u4ecb\u7ecd \u4e8b\u52a1\u7ba1\u7406\u662f\u5e94\u7528\u7cfb\u7edf\u5f00\u53d1\u4e2d\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u90e8\u5206\u3002Spring \u4e3a\u4e8b\u52a1\u7ba1\u7406\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u652f\u6301\u3002Spri [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8370"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8370"}],"version-history":[{"count":6,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8370\/revisions"}],"predecessor-version":[{"id":8389,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8370\/revisions\/8389"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}