{"id":347400,"date":"2023-03-28T09:01:22","date_gmt":"2023-03-28T09:01:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347400"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347400","title":{"rendered":"<span>@Transactional \u0432 Spring \u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a Spring&#8217;\u043e\u0432\u0430\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@Transactional<\/code> \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u041f\u0440\u043e \u044d\u0442\u043e \u043d\u0435\u043c\u0430\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/habr.com\/ru\/post\/567368\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/532000\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f, \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043e\u0442\u043a\u0430\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, \u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u0442\u043e <code>Spring<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 <code>@Transactional<\/code>, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\n<p>RuntimeException&#8217;\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043e\u0442\u043a\u0430\u0442\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, checked exception&#8217;\u044b \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442;<\/p>\n<\/li>\n<li>\n<p>RuntimeException&#8217;\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043e\u0442\u043a\u0430\u0442\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 exception \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u0435\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u044b <code>@Transactional<\/code>-\u043c\u0435\u0442\u043e\u0434\u0430. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443, \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f;<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u0438\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <code>rollbackFor<\/code> \/ <code>noRollbackFor<\/code> \u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@Transcational<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 1<\/h3>\n<pre><code class=\"java\">@Slf4j @Component public class Bean {   private final BeanRepository repository;    public Bean (BeanRepository repository) {     this.repository = repository;   }    @Transactional   public void saveItems(List&lt;Item> items) {     for(Item item: items) {       try {         saveItem(item);       } catch(RuntimeException e) {         log.error(\"Could not save item {}\", item, e);       }     }   }    @Transactional   public void saveItem(Item item) {     if(item.foo().equals(\"BAD_ITEM\"))        throw new RuntimeException();      repository.save(item);   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043e\u043a <code>Item<\/code>&#8216;\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u041d\u0415 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f BAD_ITEM&#8217;\u0430\u043c\u0438, \u0430 1-\u0439 &#8212; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f? <\/p>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>RuntimeException<\/code> \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 saveItem \u043e\u0442\u043a\u0430\u0442\u0438\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 &#8212; 3 (\u043d\u0443, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 &#8212; \u043d\u0438\u0436\u0435). \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0442\u0430\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0442\u043e\u0433\u043e \u0436\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u0430 \u043d\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u043e\u043a\u0441\u0438-\u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041e\u043d \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@Transactional<\/code> \u0443 <code>saveItem<\/code> \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u044f\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0441\u0441\u044b\u043b\u0430\u043b\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442 RuntimeException \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u0443 @Transactional-\u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c compile-time weaving, \u043b\u0438\u0431\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b \u0447\u0435\u0440\u0435\u0437 <code>inner.saveItem<\/code>, \u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 1.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 2<\/h3>\n<pre><code class=\"java\">@Component public class Bean {   private final BeanRepository repository;    public Bean(BeanRepository repository) {     this.repository = repository;   }    @Transactional   public void saveItem(Item item) {     if(item.foo().equals(\"BAD_ITEM\"))        throw new RuntimeException();      repository.save(item);   } }  @Slf4j @Controller public class Controller {   private final Bean bean;    public Controller(Bean bean) {     this.bean = bean;   }      public void saveItems(List&lt;Item> items) {     for(Item item: items) {       try {         bean.saveItem(item);       } catch(RuntimeException e) {         log.error(\"Could not save item {}\", item, e);       }     }   } }<\/code><\/pre>\n<p>\u0422\u043e\u0442 \u0436\u0435 \u0432\u043e\u043f\u0440\u043e\u0441: \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043e\u043a <code>Item<\/code>&#8216;\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u041d\u0415 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f BAD_ITEM&#8217;\u0430\u043c\u0438, \u0430 1-\u0439 &#8212; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f?<\/p>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442, \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443, 3. \u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0441 <code>RuntimeException<\/code>&#8216;\u043e\u043c \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f, \u043d\u043e \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 3 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 2 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043a\u043e\u043c\u043c\u0438\u0447\u0435\u043d\u044b.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 3<\/h3>\n<p>\u0412\u0441\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u0435\u0442\u043e\u0434 <code>saveItems<\/code> \u0442\u043e\u0436\u0435 <code>@Transactional<\/code>:<\/p>\n<pre><code class=\"java\">@Slf4j @Controller public class Controller {   ...   @Transactional   public void saveItems(List&lt;Item> items) {     for(Item item: items) {       try {         bean.saveItem(item);       } catch(RuntimeException e) {         log.error(\"Could not save item {}\", item, e);       }     }   } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 &#8212; 1. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, <code>@Transactional<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>Propagation.REQUIRED<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e <code>saveItem<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u043e\u0442\u043a\u0440\u044b\u0442\u0443\u044e \u0434\u043b\u044f <code>saveItems<\/code>. \u041f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u0430\u043a <code>rollbackOnly<\/code>.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 4<\/h3>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u0447\u0442\u043e <code>RuntimeException<\/code>&#8216;\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<pre><code class=\"java\">@Slf4j @Controller public class Controller {   ...   @Transactional(noRollbackFor = RuntimeException.class)   public void saveItems(List&lt;Item> items) {       try {         bean.saveItem(item);       } catch(RuntimeException e) {         log.error(\"Could not save item {}\", item, e);       }   } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432\u0441\u0435 \u0435\u0449\u0435 1. <code>noRollbackFor<\/code> \u0432\u043b\u0438\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u0435 &#171;\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f&#187; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u043d\u0438\u0436\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u0443 \u0436\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 <code>saveItem<\/code> \u043f\u043e\u043c\u0435\u0442\u0438\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u043a\u0430\u043a <code>rollbackOnly<\/code>.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 5<\/h3>\n<p>\u041f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043c <code>noRollbackFor<\/code> \u043d\u0430 <code>saveItem<\/code>. \u0410 \u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0443\u0431\u0435\u0440\u0435\u043c \u043a\u043e\u0434 \u043f\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044e <code>RuntimeException<\/code>.<\/p>\n<pre><code class=\"java\">@Component public class Bean {   private final BeanRepository repository;    public Bean(BeanRepository repository) {     this.repository = repository;   }    @Transactional(noRollbackFor = RuntimeException.class)   public void saveItem(Item item) {     if(item.foo().equals(\"BAD_ITEM\"))        throw new RuntimeException();      repository.save(item);   } }  @Slf4j @Controller public class Controller {   private final Bean bean;    public Controller(Bean bean) {     this.bean = bean;   }    @Transactional     public void saveItems(List&lt;Item> items) {     for(Item item: items) {       bean.saveItem(item);     }   } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 &#8212; 1. \u0414\u0430, \u0442\u0435\u043f\u0435\u0440\u044c <code>saveItem<\/code> \u043d\u0435 \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u043d\u043e \u0441 \u0441\u0430\u043c\u0438\u043c-\u0442\u043e <code>RuntimeException<\/code>&#8216;\u043e\u043c \u043e\u043d \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442. Exception \u043f\u0440\u043e\u043b\u0435\u0442\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u0438  \u0443\u0436\u0435 \u0443 \u0435\u0433\u043e <code>@Transactional<\/code>-\u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043e\u0442\u043a\u0430\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 6<\/h3>\n<p>\u041f\u043e\u043c\u0435\u0442\u0438\u043c \u043e\u0431\u0430 <code>@Transactional<\/code>-\u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043d\u0435 \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u043b\u0438 runtime-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"java\">@Component public class Bean {   private final BeanRepository repository;    public Bean(BeanRepository repository) {     this.repository = repository;   }    @Transactional(noRollbackFor = RuntimeException.class)   public void saveItem(Item item) {     if(item.foo().equals(\"BAD_ITEM\"))        throw new RuntimeException();      repository.save(item);   } }  @Slf4j @Controller public class Controller {   private final Bean bean;    public Controller(Bean bean) {     this.bean = bean;   }    @Transactional(noRollbackFor = RuntimeException.class)   public void saveItems(List&lt;Item> items) {     for(Item item: items) {       bean.saveItem(item);     }   } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 &#8212; 2. \u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f, \u043d\u043e \u0438\u0437-\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f. \u0422\u043e\u0442 \u0436\u0435 \u044d\u0444\u0444\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u0431\u0440\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@Transactional<\/code>, \u043b\u0438\u0431\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0443\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 7<\/h3>\n<p>\u0423 <code>Spring Data<\/code> \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 <code>CrudRepository<\/code> \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043c\u0435\u0442\u043e\u0434: <\/p>\n<p><code>void deleteAllById(Iterable&lt;? extends ID> ids)<\/code><\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u0435\u043c\u0443 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0434\u0438\u043d \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439? \u042f \u0431\u044b \u043e\u0436\u0438\u0434\u0430\u043b, \u0447\u0442\u043e \u043e\u043d \u0443\u0434\u0430\u043b\u0438\u0442 \u0442\u0435, \u0447\u0442\u043e \u0435\u0441\u0442\u044c, \u0438 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 (\u043d\u0443, \u043a\u0430\u043a \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>delete<\/code> \u0432 <code>SQL<\/code>). \u0418 \u0434\u0430, <code>Spring Data<\/code>, \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <code>Spring Data 3<\/code>. \u0410 \u0435\u043c\u0443 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0447\u0442\u043e-\u0442\u043e \u043e\u043a\u043e\u043b\u043e \u043f\u043e\u043b\u0443\u0433\u043e\u0434\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u043d\u043d\u044e\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 <code>EmptyResultDataAccessException<\/code> (<code>Spring Data<\/code> \u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u043b\u044e\u0434\u0438, \u0438 \u0434\u0430, \u043f\u043e\u0448\u043b\u0430 \u043e\u043d\u0430 \u043a \u0447\u0435\u0440\u0442\u0443 \u044d\u0442\u0430 \u0432\u0430\u0448\u0430 \u043e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c).<\/p>\n<pre><code class=\"java\">@Component public class Bean {   private final BeanRepository repository;    public Bean(BeanRepository repository) {     this.repository = repository;   }    @Transactional(noRollbackFor = EmptyResultDataAccessException.class)   public void deleteItems(List&lt;Item> items) {     repostory.deleteAllById(items.stream().map(Item::id).toList());   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a \u0432 <code>Spring Data 2.x<\/code>?<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f. \u0423 <code>Repository<\/code> \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0430\u043c\u0438 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a <code>@Transactional<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u043d\u043e\u043c\u0435\u0440 4.<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u0441\u0432\u043e\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>deleteAllById<\/code>, \u0443\u043a\u0430\u0437\u0430\u0432 \u0443\u0436\u0435 \u0435\u043c\u0443 <code>noRollbackFor = EmptyResultDataAccessException.class<\/code>, \u043d\u043e \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u0430\u044f \u0438\u0434\u0435\u044f. <code>deleteAllById<\/code> \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0446\u0438\u043a\u043b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>deleteById<\/code>. \u041e\u043d \u0442\u043e\u0436\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a <code>@Transactional<\/code>, \u043d\u043e \u044d\u0442\u043e \u043d\u0435\u0432\u0430\u0436\u043d\u043e, \u043a\u0430\u043a \u043c\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u043e\u043c\u0435\u0440 1. \u041a\u043e\u0433\u0434\u0430 <code>deleteById<\/code> \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f, \u043d\u043e \u0446\u0438\u043a\u043b \u043f\u0440\u0435\u0440\u0432\u0435\u0442\u0441\u044f. \u0412 \u0438\u0442\u043e\u0433\u0435, \u0432\u044b \u043e\u043a\u0430\u0436\u0435\u0442\u0435\u0441\u044c \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u043e\u043c\u0435\u0440 6, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 <code>Item<\/code>&#8216;\u043e\u0432 \u0443\u0434\u0430\u043b\u0438\u043b\u0430\u0441\u044c, \u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 &#8212; \u043d\u0435\u0442.<\/p>\n<p>\u0412\u044b\u0445\u043e\u0434 &#8212; \u043b\u0438\u0431\u043e \u0432\u043c\u0435\u0441\u0442\u043e <code>deleteAllById<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0447\u0442\u043e <code>Item<\/code> \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>deleteById<\/code>, \u043b\u0438\u0431\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u043c <code>JPQL<\/code>-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 8<\/h3>\n<pre><code class=\"java\">public interface BeanRepository extends JpaRepository&lt;Item, Long> {    @Override   @Transactional(noRollbackForClassName = \"org.springframework.dao.EmptyResultDataAccessException\", rollbackFor = DataAccessException.class, noRollbackFor = RuntimeException.class)   void deleteAllById(Iterable&lt;? extends Long> longs); }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0438\u0437 \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a\u043e\u0432 \u043d\u0435\u0442?<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0443, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0430\u0432\u0442\u043e\u0440\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0443\u043b-\u0440\u0435\u043a\u0432\u0435\u0441\u0442\u0430, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043f\u043e\u0431\u044c\u044e\u0442 \u043d\u0430 code-review. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u043e\u0433\u0430\u043c\u0438. <\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 &#8212; \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0431\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u0433\u043e <code>Exception<\/code>&#8216;\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; <code>noRollbackForClassName<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0447\u0430\u0441\u0442\u044c <code>Item<\/code>&#8216;\u043e\u0432 \u0443\u0434\u0430\u043b\u0438\u0442\u0441\u044f, \u0447\u0430\u0441\u0442\u044c &#8212; \u043d\u0435\u0442.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043d\u0435\u0442 \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u0430\u0432\u0438\u043b, \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 (<code>RuntimeException<\/code> \u0438 <code>Error<\/code> \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u043c, checked &#8212; \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u0435\u043c). \u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0443\u043f\u043e\u0440\u043e\u0442\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435  <code>rollbackFor = RuntimeException.class, noRollbackFor = RuntimeException.class<\/code>. <code>Spring<\/code> \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u00a0\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u044d\u0442\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e. \u0421\u0443\u0434\u044f \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443, \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 noRollback-\u043f\u0440\u0430\u0432\u0438\u043b\u0430.<\/p>\n<\/div>\n<\/details>\n<h2>\u0418\u0442\u043e\u0433\u0438<\/h2>\n<ol>\n<li>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b <code>rollbackFor<\/code> \/ <code>noRollbackFor<\/code> \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0421\u0430\u043c\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u0448\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b rollbackFor \/ noRollbackFor \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f <code>@Transactional<\/code>-\u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043d\u0438\u0436\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>Propagation.REQUIRED<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0432\u0441\u0435\u0440\u044c\u0435\u0437 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435\u043c \u044d\u0442\u0438\u043c, \u0442\u043e \u0437\u0430\u0434\u0443\u043c\u0430\u0439\u0442\u0435\u0441\u044c, \u0430 \u043d\u0443\u0436\u043d\u044b \u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438. \u041f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u0440\u0443\u0447\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043b\u043e\u0433\u0438\u043a\u043e\u0439, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/725064\/\"> https:\/\/habr.com\/ru\/post\/725064\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a Spring&#8217;\u043e\u0432\u0430\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@Transactional<\/code> \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u041f\u0440\u043e \u044d\u0442\u043e \u043d\u0435\u043c\u0430\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/habr.com\/ru\/post\/567368\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/532000\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f, \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043e\u0442\u043a\u0430\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, \u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u0442\u043e <code>Spring<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 <code>@Transactional<\/code>, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\n<p>RuntimeException&#8217;\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043e\u0442\u043a\u0430\u0442\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, checked exception&#8217;\u044b \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442;<\/p>\n<\/li>\n<li>\n<p>RuntimeException&#8217;\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043e\u0442\u043a\u0430\u0442\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 exception \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u0435\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u044b <code>@Transactional<\/code>-\u043c\u0435\u0442\u043e\u0434\u0430. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443, \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f;<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u0438\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <code>rollbackFor<\/code> \/ <code>noRollbackFor<\/code> \u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@Transcational<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 1<\/h3>\n<pre><code class=\"java\">@Slf4j @Component public class Bean {   private final BeanRepository repository;    public Bean (BeanRepository repository) {     this.repository = repository;   }    @Transactional   public void saveItems(List&lt;Item> items) {     for(Item item: items) {       try {         saveItem(item);       } catch(RuntimeException e) {         log.error(\"Could not save item {}\", item, e);       }     }   }    @Transactional   public void saveItem(Item item) {     if(item.foo().equals(\"BAD_ITEM\"))        throw new RuntimeException();      repository.save(item);   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043e\u043a <code>Item<\/code>&#8216;\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u041d\u0415 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f BAD_ITEM&#8217;\u0430\u043c\u0438, \u0430 1-\u0439 &#8212; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f? <\/p>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>RuntimeException<\/code> \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 saveItem \u043e\u0442\u043a\u0430\u0442\u0438\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 &#8212; 3 (\u043d\u0443, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 &#8212; \u043d\u0438\u0436\u0435). \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0442\u0430\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0442\u043e\u0433\u043e \u0436\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u0430 \u043d\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u043e\u043a\u0441\u0438-\u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041e\u043d \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@Transactional<\/code> \u0443 <code>saveItem<\/code> \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u044f\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0441\u0441\u044b\u043b\u0430\u043b\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442 RuntimeException \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u0443 @Transactional-\u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c compile-time weaving, \u043b\u0438\u0431\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b \u0447\u0435\u0440\u0435\u0437 <code>inner.saveItem<\/code>, \u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 1.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 2<\/h3>\n<pre><code class=\"java\">@Component public class Bean {   private final BeanRepository repository;    public Bean(BeanRepository repository) {     this.repository = repository;   }    @Transactional   public void saveItem(Item item) {     if(item.foo().equals(\"BAD_ITEM\"))        throw new RuntimeException();      repository.save(item);   } }  @Slf4j @Controller public class Controller {   private final Bean bean;    public Controller(Bean bean) {     this.bean = bean;   }      public void saveItems(List&lt;Item> items) {     for(Item item: items) {       try {         bean.saveItem(item);       } catch(RuntimeException e) {         log.error(\"Could not save item {}\", item, e);       }     }   } }<\/code><\/pre>\n<p>\u0422\u043e\u0442 \u0436\u0435 \u0432\u043e\u043f\u0440\u043e\u0441: \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043e\u043a <code>Item<\/code>&#8216;\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u041d\u0415 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f BAD_ITEM&#8217;\u0430\u043c\u0438, \u0430 1-\u0439 &#8212; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f?<\/p>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442, \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443, 3. \u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u0441 <code>RuntimeException<\/code>&#8216;\u043e\u043c \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f, \u043d\u043e \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 3 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 2 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043a\u043e\u043c\u043c\u0438\u0447\u0435\u043d\u044b.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 3<\/h3>\n<p>\u0412\u0441\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u0435\u0442\u043e\u0434 <code>saveItems<\/code> \u0442\u043e\u0436\u0435 <code>@Transactional<\/code>:<\/p>\n<pre><code class=\"java\">@Slf4j @Controller public class Controller {   ...   @Transactional   public void saveItems(List&lt;Item> items) {     for(Item item: items) {       try {         bean.saveItem(item);       } catch(RuntimeException e) {         log.error(\"Could not save item {}\", item, e);       }     }   } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 &#8212; 1. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, <code>@Transactional<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>Propagation.REQUIRED<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e <code>saveItem<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u043e\u0442\u043a\u0440\u044b\u0442\u0443\u044e \u0434\u043b\u044f <code>saveItems<\/code>. \u041f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u0430\u043a <code>rollbackOnly<\/code>.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 4<\/h3>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u0447\u0442\u043e <code>RuntimeException<\/code>&#8216;\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<pre><code class=\"java\">@Slf4j @Controller public class Controller {   ...   @Transactional(noRollbackFor = RuntimeException.class)   public void saveItems(List&lt;Item> items) {       try {         bean.saveItem(item);       } catch(RuntimeException e) {         log.error(\"Could not save item {}\", item, e);       }   } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432\u0441\u0435 \u0435\u0449\u0435 1. <code>noRollbackFor<\/code> \u0432\u043b\u0438\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u0435 &#171;\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f&#187; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u043d\u0438\u0436\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u0443 \u0436\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 <code>saveItem<\/code> \u043f\u043e\u043c\u0435\u0442\u0438\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e \u043a\u0430\u043a <code>rollbackOnly<\/code>.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 5<\/h3>\n<p>\u041f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043c <code>noRollbackFor<\/code> \u043d\u0430 <code>saveItem<\/code>. \u0410 \u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0443\u0431\u0435\u0440\u0435\u043c \u043a\u043e\u0434 \u043f\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044e <code>RuntimeException<\/code>.<\/p>\n<pre><code class=\"java\">@Component public class Bean {   private final BeanRepository repository;    public Bean(BeanRepository repository) {     this.repository = repository;   }    @Transactional(noRollbackFor = RuntimeException.class)   public void saveItem(Item item) {     if(item.foo().equals(\"BAD_ITEM\"))        throw new RuntimeException();      repository.save(item);   } }  @Slf4j @Controller public class Controller {   private final Bean bean;    public Controller(Bean bean) {     this.bean = bean;   }    @Transactional     public void saveItems(List&lt;Item> items) {     for(Item item: items) {       bean.saveItem(item);     }   } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 &#8212; 1. \u0414\u0430, \u0442\u0435\u043f\u0435\u0440\u044c <code>saveItem<\/code> \u043d\u0435 \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u043d\u043e \u0441 \u0441\u0430\u043c\u0438\u043c-\u0442\u043e <code>RuntimeException<\/code>&#8216;\u043e\u043c \u043e\u043d \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442. Exception \u043f\u0440\u043e\u043b\u0435\u0442\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u0438  \u0443\u0436\u0435 \u0443 \u0435\u0433\u043e <code>@Transactional<\/code>-\u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043e\u0442\u043a\u0430\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 6<\/h3>\n<p>\u041f\u043e\u043c\u0435\u0442\u0438\u043c \u043e\u0431\u0430 <code>@Transactional<\/code>-\u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043d\u0435 \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u043b\u0438 runtime-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"java\">@Component public class Bean {   private final BeanRepository repository;    public Bean(BeanRepository repository) {     this.repository = repository;   }    @Transactional(noRollbackFor = RuntimeException.class)   public void saveItem(Item item) {     if(item.foo().equals(\"BAD_ITEM\"))        throw new RuntimeException();      repository.save(item);   } }  @Slf4j @Controller public class Controller {   private final Bean bean;    public Controller(Bean bean) {     this.bean = bean;   }    @Transactional(noRollbackFor = RuntimeException.class)   public void saveItems(List&lt;Item> items) {     for(Item item: items) {       bean.saveItem(item);     }   } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e 0-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d 0-\u0439 \u0438 2-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 &#8212; 2. \u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f, \u043d\u043e \u0438\u0437-\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f. \u0422\u043e\u0442 \u0436\u0435 \u044d\u0444\u0444\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u0431\u0440\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@Transactional<\/code>, \u043b\u0438\u0431\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0443\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 7<\/h3>\n<p>\u0423 <code>Spring Data<\/code> \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 <code>CrudRepository<\/code> \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043c\u0435\u0442\u043e\u0434: <\/p>\n<p><code>void deleteAllById(Iterable&lt;? extends ID> ids)<\/code><\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u0435\u043c\u0443 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0434\u0438\u043d \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439? \u042f \u0431\u044b \u043e\u0436\u0438\u0434\u0430\u043b, \u0447\u0442\u043e \u043e\u043d \u0443\u0434\u0430\u043b\u0438\u0442 \u0442\u0435, \u0447\u0442\u043e \u0435\u0441\u0442\u044c, \u0438 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 (\u043d\u0443, \u043a\u0430\u043a \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>delete<\/code> \u0432 <code>SQL<\/code>). \u0418 \u0434\u0430, <code>Spring Data<\/code>, \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <code>Spring Data 3<\/code>. \u0410 \u0435\u043c\u0443 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0447\u0442\u043e-\u0442\u043e \u043e\u043a\u043e\u043b\u043e \u043f\u043e\u043b\u0443\u0433\u043e\u0434\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u043d\u043d\u044e\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 <code>EmptyResultDataAccessException<\/code> (<code>Spring Data<\/code> \u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u043b\u044e\u0434\u0438, \u0438 \u0434\u0430, \u043f\u043e\u0448\u043b\u0430 \u043e\u043d\u0430 \u043a \u0447\u0435\u0440\u0442\u0443 \u044d\u0442\u0430 \u0432\u0430\u0448\u0430 \u043e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c).<\/p>\n<pre><code class=\"java\">@Component public class Bean {   private final BeanRepository repository;    public Bean(BeanRepository repository) {     this.repository = repository;   }    @Transactional(noRollbackFor = EmptyResultDataAccessException.class)   public void deleteItems(List&lt;Item> items) {     repostory.deleteAllById(items.stream().map(Item::id).toList());   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a \u0432 <code>Spring Data 2.x<\/code>?<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f. \u0423 <code>Repository<\/code> \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0430\u043c\u0438 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a <code>@Transactional<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u043d\u043e\u043c\u0435\u0440 4.<\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u0441\u0432\u043e\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>deleteAllById<\/code>, \u0443\u043a\u0430\u0437\u0430\u0432 \u0443\u0436\u0435 \u0435\u043c\u0443 <code>noRollbackFor = EmptyResultDataAccessException.class<\/code>, \u043d\u043e \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u0430\u044f \u0438\u0434\u0435\u044f. <code>deleteAllById<\/code> \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0446\u0438\u043a\u043b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>deleteById<\/code>. \u041e\u043d \u0442\u043e\u0436\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a <code>@Transactional<\/code>, \u043d\u043e \u044d\u0442\u043e \u043d\u0435\u0432\u0430\u0436\u043d\u043e, \u043a\u0430\u043a \u043c\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u043e\u043c\u0435\u0440 1. \u041a\u043e\u0433\u0434\u0430 <code>deleteById<\/code> \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f \u043d\u0435 \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u0441\u044f, \u043d\u043e \u0446\u0438\u043a\u043b \u043f\u0440\u0435\u0440\u0432\u0435\u0442\u0441\u044f. \u0412 \u0438\u0442\u043e\u0433\u0435, \u0432\u044b \u043e\u043a\u0430\u0436\u0435\u0442\u0435\u0441\u044c \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u043e\u043c\u0435\u0440 6, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 <code>Item<\/code>&#8216;\u043e\u0432 \u0443\u0434\u0430\u043b\u0438\u043b\u0430\u0441\u044c, \u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 &#8212; \u043d\u0435\u0442.<\/p>\n<p>\u0412\u044b\u0445\u043e\u0434 &#8212; \u043b\u0438\u0431\u043e \u0432\u043c\u0435\u0441\u0442\u043e <code>deleteAllById<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0447\u0442\u043e <code>Item<\/code> \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>deleteById<\/code>, \u043b\u0438\u0431\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u043c <code>JPQL<\/code>-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.<\/p>\n<\/div>\n<\/details>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 8<\/h3>\n<pre><code class=\"java\">public interface BeanRepository extends JpaRepository&lt;Item, Long> {    @Override   @Transactional(noRollbackForClassName = \"org.springframework.dao.EmptyResultDataAccessException\", rollbackFor = DataAccessException.class, noRollbackFor = RuntimeException.class)   void deleteAllById(Iterable&lt;? extends Long> longs); }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0438\u0437 \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a\u043e\u0432 \u043d\u0435\u0442?<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0443, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0430\u0432\u0442\u043e\u0440\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0443\u043b-\u0440\u0435\u043a\u0432\u0435\u0441\u0442\u0430, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043f\u043e\u0431\u044c\u044e\u0442 \u043d\u0430 code-review. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u043e\u0433\u0430\u043c\u0438. <\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 &#8212; \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0431\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u0433\u043e <code>Exception<\/code>&#8216;\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; <code>noRollbackForClassName<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0447\u0430\u0441\u0442\u044c <code>Item<\/code>&#8216;\u043e\u0432 \u0443\u0434\u0430\u043b\u0438\u0442\u0441\u044f, \u0447\u0430\u0441\u0442\u044c &#8212; \u043d\u0435\u0442.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043d\u0435\u0442 \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u0430\u0432\u0438\u043b, \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 (<code>RuntimeException<\/code> \u0438 <code>Error<\/code> \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u043c, checked &#8212; \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u0435\u043c). \u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0443\u043f\u043e\u0440\u043e\u0442\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435  <code>rollbackFor = RuntimeException.class, noRollbackFor = RuntimeException.class<\/code>. <code>Spring<\/code> \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u00a0\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u044d\u0442\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e. \u0421\u0443\u0434\u044f \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443, \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 noRollback-\u043f\u0440\u0430\u0432\u0438\u043b\u0430.<\/p>\n<\/div>\n<\/details>\n<h2>\u0418\u0442\u043e\u0433\u0438<\/h2>\n<ol>\n<li>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b <code>rollbackFor<\/code> \/ <code>noRollbackFor<\/code> \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0421\u0430\u043c\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u0448\u0435 \u043f\u043e \u0441\u0442\u0435\u043a\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-347400","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347400"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347400\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}