{"id":428130,"date":"2024-08-02T21:00:15","date_gmt":"2024-08-02T21:00:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=428130"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=428130","title":{"rendered":"<span>\u041a\u044d\u0448 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f Hibernate \u0434\u043b\u044f \u0447\u0430\u0439\u043d\u0438\u043a\u043e\u0432<\/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>\u0411\u0443\u0434\u0443\u0447\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0438\u043b\u0438 \u0441\u0442\u0430\u0436\u0435\u0440\u043e\u043c, \u0432\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u0442\u0435\u0441\u044c \u0441 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u2014 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043d\u0430 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f\u0445 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e \u043a\u0443\u0441\u043e\u0447\u043a\u0430\u043c \u0438\u0437 \u0441\u0442\u0430\u0442\u0435\u0439 \u0434\u0435\u0441\u044f\u0442\u0438\u043b\u0435\u0442\u043d\u0435\u0439 \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438, \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 stackoverflow \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f-\u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0435\u0440\u0435\u0434 \u0441\u043e\u0431\u043e\u0439 \u0446\u0435\u043b\u044c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0438 \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u044d\u0448 \u0432 Hibernate 6. <\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0430\u0432\u0442\u043e\u0440 \u0441\u043e\u0432\u0435\u0442\u0443\u0435\u0442 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/articles\/135176\/\" rel=\"noopener noreferrer nofollow\">\u0432\u043e\u0442 \u044d\u0442\u0443<\/a> \u0441\u0442\u0430\u0442\u044c\u044e \u0441 \u0442\u0435\u043e\u0440\u0438\u0435\u0439, \u0445\u043e\u0442\u044f \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0435\u0439 \u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u043b\u043e\u0441\u044c \u0446\u0435\u043b\u044b\u0445 12 \u043b\u0435\u0442:)<\/p>\n<h3>\u041f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438<\/h3>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u043c\u0435\u043d\u044e. \u041e\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0447\u0430\u0441\u0442\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0436\u0435 \u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0443.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0430\u0439\u0442\u0435\u043c\u043e\u0432:<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"menu_items\") public class MenuItemEntity {      @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     @Column(name = \"id\", nullable = false)     private Long id;      @Column(name = \"name\", nullable = false)     private String name;      @Column(name = \"calories\", nullable = false)     private Integer calories;      @Column(name = \"price\", nullable = false)     private Double price;  }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u0435\u043d\u044e 3 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441 id = 1. \u0423\u0441\u043f\u0435\u0445!<\/p>\n<pre><code class=\"json\">{     \"id\": 1,     \"name\": \"bread\",     \"calories\": 500,     \"price\": 50.0 }<\/code><\/pre>\n<p>\u041d\u043e\u043e&#8230; <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b70\/33d\/a35\/b7033da359a951c7341779792500778f.png\" alt=\"\u041b\u043e\u0433\u0438 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435\" title=\"\u041b\u043e\u0433\u0438 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435\" width=\"1106\" height=\"82\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b70\/33d\/a35\/b7033da359a951c7341779792500778f.png\"\/><\/p>\n<div><figcaption>\u041b\u043e\u0433\u0438 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041b\u043e\u0433\u0438\u0447\u043d\u043e \u2014 \u043c\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043b\u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043a\u044d\u0448!<\/p>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u044d\u0448\u0430 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f<\/h3>\n<p>Hibernate \u043d\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e  L2 \u043a\u044d\u0448\u0430 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u2014 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u0421\u0430\u043c\u044b\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u044b <a href=\"https:\/\/docs.jboss.org\/hibernate\/core\/3.3\/reference\/en\/html\/performance.html#performance-cache\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u041c\u044b \u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ehcache.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 pom.xml \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"xml\">        &lt;dependency&gt;             &lt;groupId&gt;org.hibernate&lt;\/groupId&gt;             &lt;artifactId&gt;hibernate-core&lt;\/artifactId&gt;             &lt;version&gt;6.4.1.Final&lt;\/version&gt;         &lt;\/dependency&gt;         &lt;dependency&gt;             &lt;groupId&gt;org.hibernate&lt;\/groupId&gt;             &lt;artifactId&gt;hibernate-jcache&lt;\/artifactId&gt;             &lt;version&gt;6.4.1.Final&lt;\/version&gt;         &lt;\/dependency&gt;         &lt;dependency&gt;             &lt;groupId&gt;org.ehcache&lt;\/groupId&gt;             &lt;artifactId&gt;ehcache&lt;\/artifactId&gt;             &lt;version&gt;3.10.0&lt;\/version&gt;             &lt;classifier&gt;jakarta&lt;\/classifier&gt;         &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0418 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0444\u0430\u0439\u043b application.yml (application.properties), \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0442\u044c Hibernate \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c L2 \u043a\u044d\u0448 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"yaml\">  jpa:     properties:       hibernate:         javax.cache:           provider: org.ehcache.jsr107.EhcacheCachingProvider           uri: ehcache.xml         cache:           use_second_level_cache: true           region.factory_class: jcache<\/code><\/pre>\n<ul>\n<li>\n<p><em>use_second_level_cache<\/em> \u2014 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043a\u044d\u0448 2 \u0443\u0440\u043e\u0432\u043d\u044f<\/p>\n<\/li>\n<li>\n<p><em>provider <\/em>\u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438) \u043a\u044d\u0448\u0430<\/p>\n<\/li>\n<li>\n<p><em>uri <\/em>\u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p><em>region.factory_class <\/em>\u2014 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c ehcache.xml. \u041f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/www.ehcache.org\/generated\/2.10.0\/html\/ehc-all\/index.html#page\/Ehcache_Documentation_Set%2Fco-hib_configuring_ehcache_settings.html%23\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>, \u043d\u0430\u043c \u0436\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u0432\u0441\u0435\u0433\u043e 3 \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0441\u0440\u043e\u043a\u0430 \u0436\u0438\u0437\u043d\u0438 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0445\u0438\u043f\u0430. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0432\u0438\u0434\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043a \u043a\u044d\u0448\u0443 MenuItemEntity:<\/p>\n<pre><code class=\"xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt; &lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"         xmlns=\"http:\/\/www.ehcache.org\/v3\"         xsi:schemaLocation=\"http:\/\/www.ehcache.org\/v3 http:\/\/www.ehcache.org\/schema\/ehcache-core-3.0.xsd\"&gt;      &lt;cache-template name=\"default\"&gt;         &lt;expiry&gt;             &lt;ttl unit=\"days\"&gt;1&lt;\/ttl&gt;         &lt;\/expiry&gt;         &lt;heap&gt;1000&lt;\/heap&gt;     &lt;\/cache-template&gt;      &lt;cache alias=\"com.example.cache_for_dummies.entity.MenuItemEntity\" uses-template=\"default\"\/&gt;  &lt;\/config&gt;<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445: \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c MenuItemEntity, \u043a\u0430\u043a \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u2014 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <em>org.hibernate.annotations.Cache:<\/em><\/p>\n<pre><code class=\"java\">@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 usage \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>READ-ONLY \u2014  \u0445\u043e\u0440\u043e\u0448\u0430 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0430\u0441\u0442\u043e \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f;<\/p>\n<\/li>\n<li>\n<p>READ-WRITE \u2014 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435;<\/p>\n<\/li>\n<li>\n<p>NONSTRICT READ-WRITE \u2014 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u0435\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u0430\u043a \u0447\u0430\u0441\u0442\u043e, \u0438 \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0434\u0432\u0443\u043c\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438;<\/p>\n<\/li>\n<li>\n<p>TRANSACTIONAL \u2014 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 JTA-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e usage, \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Cache \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"126\" width=\"126\">\n<p align=\"center\">\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"center\">\u0422\u0438\u043f<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"126\" width=\"126\">\n<p align=\"left\">includeLazy<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">boolean<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0431\u0443\u0434\u0443\u0442 \u043b\u0438 lazy \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u043a\u044d\u0448 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u0445 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e true<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"126\" width=\"126\">\n<p align=\"left\">region<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">String<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0420\u0435\u0433\u0438\u043e\u043d \u043a\u044d\u0448\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0432\u0435\u043d \u043f\u043e\u043b\u043d\u043e\u043c\u0443 \u0438\u043c\u0435\u043d\u0438 \u043a\u043b\u0430\u0441\u0441\u0430<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0435 \u0436\u0435 3 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u043c\u0435\u043d\u044e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7cd\/6b6\/2ff\/7cd6b62ff9a5654b13812551f9589766.png\" alt=\"\u041a \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435.\" title=\"\u041a \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435.\" width=\"1118\" height=\"52\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7cd\/6b6\/2ff\/7cd6b62ff9a5654b13812551f9589766.png\"\/><\/p>\n<div><figcaption>\u041a \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435.<\/figcaption><\/div>\n<\/figure>\n<p>\u041a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u044b\u043b\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u043b\u0438 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u043a\u044d\u0448\u0430 \u2014 \u0443\u0440\u0430! \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c getAll, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u043c\u0435\u043d\u044e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/96a\/c4c\/380\/96ac4c3803586c62ebe1593865fea78f.png\" alt=\"\u041e\u0439-\u0451\u0439!\" title=\"\u041e\u0439-\u0451\u0439!\" width=\"933\" height=\"111\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/96a\/c4c\/380\/96ac4c3803586c62ebe1593865fea78f.png\"\/><\/p>\n<div><figcaption>\u041e\u0439-\u0451\u0439!<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043a\u044d\u0448 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u0430\u0436\u0434\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u0432 \u0431\u0430\u0437\u0443.<\/p>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?<\/h3>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0438\u0445 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443, \u0442\u043e \u0435\u0441\u0442\u044c id. Hibernate \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0430\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u2014 \u043e\u043d \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u0445 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u043c, \u043a\u0430\u043a \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0433\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c &#171;find all&#187;, hibernate \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 all, \u0438 \u0438\u0434\u0435\u0442 \u0437\u0430 \u044d\u0442\u0438\u043c \u0432 \u0431\u0430\u0437\u0443.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c <em>\u043a\u044d\u0448 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <\/em>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e:<\/p>\n<ol>\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u043c \u043a\u044d\u0448 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 application.properties \/ application.yml: <\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"yaml\">cache:   use_query_cache: true<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0421\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c \u043a\u044d\u0448 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 ehcache.xml (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d):<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"xml\">&lt;cache alias=\"org.hibernate.cache.internal.StandardQueryCache\"        uses-template=\"default\"\/&gt;<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u041f\u043e\u043c\u0435\u0442\u0438\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u043a\u0430\u043a \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0435. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e findAll:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"java\">public interface MenuItemRepository extends JpaRepository&lt;MenuItemEntity, Long&gt; {      @Override     @QueryHints(@QueryHint(name = AvailableHints.HINT_CACHEABLE, value = \"true\"))     List&lt;MenuItemEntity&gt; findAll();  }<\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u0412 \u043b\u043e\u0433\u0430\u0445 \u0432\u0438\u0434\u0438\u043c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/773\/042\/0fb\/7730420fbc89aa2683fae5ad9b3cd10a.png\" width=\"955\" height=\"53\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/773\/042\/0fb\/7730420fbc89aa2683fae5ad9b3cd10a.png\"\/><\/figure>\n<h3>\u041f\u0440\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438<\/h3>\n<p>\u0420\u0435\u0441\u0442\u043e\u0440\u0430\u043d \u043d\u0430\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0438\u043b\u0438\u0430\u043b\u043e\u0432 \u2014 \u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043d\u0438\u0445 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u0435\u043d\u044e \u0432 \u0440\u0435\u0441\u0442\u043e\u0440\u0430\u043d\u0430\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c, \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u0432 \u043a\u0430\u043a\u0438\u0445 \u0440\u0435\u0441\u0442\u043e\u0440\u0430\u043d\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0442\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0435 \u0431\u043b\u044e\u0434\u043e. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u043e\u0432\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c RestaurantEntity:<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"restaurants\") public class RestaurantEntity {     @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     @Column(name = \"id\", nullable = false)     private Long id;      @Column(name = \"name\", nullable = false)     private String name;      @ManyToMany     @JoinTable(name = \"restaurants_items\",             joinColumns = @JoinColumn(name = \"restaurant_id\"),             inverseJoinColumns = @JoinColumn(name = \"item_id\"))     private List&lt;MenuItemEntity&gt; menu;  }<\/code><\/pre>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c MenuItemEntity:<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"menu_items\") @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) public class MenuItemEntity {      @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     @Column(name = \"id\", nullable = false)     private Long id;      @Column(name = \"name\", nullable = false)     private String name;      @Column(name = \"calories\", nullable = false)     private Integer calories;      @Column(name = \"price\", nullable = false)     private Double price;      @ManyToMany(mappedBy = \"restaurants\")     private List&lt;RestaurantEntity&gt; restaurants;  }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0420\u0430\u0434\u0443\u0435\u043c\u0441\u044f, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"json\">{     \"id\": 2,     \"name\": \"beer\",     \"calories\": 400,     \"price\": 350.0,     \"restaurants\": [         {             \"id\": 2,             \"name\": \"Restaurant 2\"         }     ] }<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u043b\u043e\u0433\u0438 \u0438 \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e, \u0445\u043e\u0442\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 menu_items \u0431\u044b\u043b\u043e \u0432\u0441\u0435\u0433\u043e 1 \u0440\u0430\u0437, \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 restaurants_items \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7e6\/fed\/166\/7e6fed1661d84b8ad79fc1a38e8e92cf.png\" width=\"1514\" height=\"117\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7e6\/fed\/166\/7e6fed1661d84b8ad79fc1a38e8e92cf.png\"\/><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/55e\/14c\/87a\/55e14c87ae9dd9c4ed3aa991d458a5c9.jpg\" alt=\"\u0418 \u043e\u043f\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a MenuItemEntity \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445...\" title=\"\u0418 \u043e\u043f\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a MenuItemEntity \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445...\" width=\"1920\" height=\"1440\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/55e\/14c\/87a\/55e14c87ae9dd9c4ed3aa991d458a5c9.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u0418 \u043e\u043f\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a MenuItemEntity \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445&#8230;<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043d\u0435 \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u2014 \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u0441\u0435 \u0442\u043e\u0439 \u0436\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Cache: <\/p>\n<pre><code class=\"java\">@ManyToMany(mappedBy = \"menu\") @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) private List&lt;RestaurantEntity&gt; restaurants;<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6d9\/5db\/382\/6d95db3821160c8896ae48897c440c79.png\" width=\"1512\" height=\"178\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6d9\/5db\/382\/6d95db3821160c8896ae48897c440c79.png\"\/><\/figure>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0435\u043d\u0430 \u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0432\u044f\u0437\u044c \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 restaurants_items \u0442\u043e\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u044d\u0448\u0435:) \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 One-To-Many \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f Many-To-Many \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0443\u0436\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 restaurants, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 restaurants_items. \u041d\u043e \u0438 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c, \u043f\u043e\u0432\u0435\u0441\u0438\u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @Cacheable \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c RestaurantEntity:<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"restaurants\") @Cacheable public class RestaurantEntity {<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dcc\/b24\/80b\/dccb2480b0419de2e0f0f0a7d7a9ca7f.png\" alt=\"\u0412\u0443\u0430\u043b\u044f!\" title=\"\u0412\u0443\u0430\u043b\u044f!\" width=\"1511\" height=\"59\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dcc\/b24\/80b\/dccb2480b0419de2e0f0f0a7d7a9ca7f.png\"\/><\/p>\n<div><figcaption>\u0412\u0443\u0430\u043b\u044f!<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0442\u043e\u043d\u043e\u043c \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 @Cache \u0438 @Cacheable \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0434\u043b\u044f com.example.cache_for_dummies.entity.MenuItemEntity.restaurants \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u044d\u0448 \u2014 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 ehcache.xml, \u0438\u043b\u0438 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c region. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"java\">@ManyToMany(mappedBy = \"menu\") @Cache(usage = CacheConcurrencyStrategy.READ_ONLY,         region = \"com.example.cache_for_dummies.entity.MenuItemEntity\") private List&lt;RestaurantEntity&gt; restaurants;<\/code><\/pre>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u044d\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"json\">{     \"id\": 2,     \"name\": \"Restaurant 2\",     \"menu\": [         {             \"id\": 2,             \"name\": \"beer\",             \"calories\": 400,             \"price\": 350.0         },         {             \"id\": 4,             \"name\": \"ribs\",             \"calories\": 700,             \"price\": 800.0         }     ] }<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ccb\/a37\/369\/ccba3736916d48d3a4201e69eb94fdbe.png\" alt=\"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f restaurants \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043a\u044d\u0448, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f menu_items \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 join, \u0430 \u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.\" title=\"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f restaurants \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043a\u044d\u0448, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f menu_items \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 join, \u0430 \u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.\" width=\"1652\" height=\"169\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ccb\/a37\/369\/ccba3736916d48d3a4201e69eb94fdbe.png\"\/><\/p>\n<div><figcaption>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f restaurants \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043a\u044d\u0448, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f menu_items \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 join, \u0430 \u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.<\/figcaption><\/div>\n<\/figure>\n<p>\u26a0\ufe0f \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 List&lt;MenuItemEntity&gt; menu \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @Cache, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043e\u0434\u043d\u0430\u043a\u043e \u043a\u044d\u0448 \u0441\u043e\u0437\u0434\u0430\u0441\u0442\u0441\u044f \u0438 \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 RestaurantEntity!<\/p>\n<hr\/>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u043e\u044f\u0441\u043d\u0438\u043b\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u044d\u0448\u0430 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432 Hibernate. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u043e\u0442 <a href=\"https:\/\/github.com\/Xentention\/cache_for_dummies\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\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\/articles\/833478\/\"> https:\/\/habr.com\/ru\/articles\/833478\/<\/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>\u0411\u0443\u0434\u0443\u0447\u0438 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u0438\u043b\u0438 \u0441\u0442\u0430\u0436\u0435\u0440\u043e\u043c, \u0432\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u0442\u0435\u0441\u044c \u0441 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u2014 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043d\u0430 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f\u0445 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e \u043a\u0443\u0441\u043e\u0447\u043a\u0430\u043c \u0438\u0437 \u0441\u0442\u0430\u0442\u0435\u0439 \u0434\u0435\u0441\u044f\u0442\u0438\u043b\u0435\u0442\u043d\u0435\u0439 \u0434\u0430\u0432\u043d\u043e\u0441\u0442\u0438, \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 stackoverflow \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f-\u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0435\u0440\u0435\u0434 \u0441\u043e\u0431\u043e\u0439 \u0446\u0435\u043b\u044c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0438 \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u044d\u0448 \u0432 Hibernate 6. <\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0430\u0432\u0442\u043e\u0440 \u0441\u043e\u0432\u0435\u0442\u0443\u0435\u0442 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/articles\/135176\/\" rel=\"noopener noreferrer nofollow\">\u0432\u043e\u0442 \u044d\u0442\u0443<\/a> \u0441\u0442\u0430\u0442\u044c\u044e \u0441 \u0442\u0435\u043e\u0440\u0438\u0435\u0439, \u0445\u043e\u0442\u044f \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0435\u0439 \u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u043b\u043e\u0441\u044c \u0446\u0435\u043b\u044b\u0445 12 \u043b\u0435\u0442:)<\/p>\n<h3>\u041f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438<\/h3>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u043c\u0435\u043d\u044e. \u041e\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0447\u0430\u0441\u0442\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0436\u0435 \u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0443.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0430\u0439\u0442\u0435\u043c\u043e\u0432:<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"menu_items\") public class MenuItemEntity {      @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     @Column(name = \"id\", nullable = false)     private Long id;      @Column(name = \"name\", nullable = false)     private String name;      @Column(name = \"calories\", nullable = false)     private Integer calories;      @Column(name = \"price\", nullable = false)     private Double price;  }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u0435\u043d\u044e 3 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441 id = 1. \u0423\u0441\u043f\u0435\u0445!<\/p>\n<pre><code class=\"json\">{     \"id\": 1,     \"name\": \"bread\",     \"calories\": 500,     \"price\": 50.0 }<\/code><\/pre>\n<p>\u041d\u043e\u043e&#8230; <\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041b\u043e\u0433\u0438 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041b\u043e\u0433\u0438\u0447\u043d\u043e \u2014 \u043c\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043b\u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043a\u044d\u0448!<\/p>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u044d\u0448\u0430 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f<\/h3>\n<p>Hibernate \u043d\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e  L2 \u043a\u044d\u0448\u0430 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u2014 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u0421\u0430\u043c\u044b\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u044b <a href=\"https:\/\/docs.jboss.org\/hibernate\/core\/3.3\/reference\/en\/html\/performance.html#performance-cache\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u041c\u044b \u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ehcache.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 pom.xml \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"xml\">        &lt;dependency&gt;             &lt;groupId&gt;org.hibernate&lt;\/groupId&gt;             &lt;artifactId&gt;hibernate-core&lt;\/artifactId&gt;             &lt;version&gt;6.4.1.Final&lt;\/version&gt;         &lt;\/dependency&gt;         &lt;dependency&gt;             &lt;groupId&gt;org.hibernate&lt;\/groupId&gt;             &lt;artifactId&gt;hibernate-jcache&lt;\/artifactId&gt;             &lt;version&gt;6.4.1.Final&lt;\/version&gt;         &lt;\/dependency&gt;         &lt;dependency&gt;             &lt;groupId&gt;org.ehcache&lt;\/groupId&gt;             &lt;artifactId&gt;ehcache&lt;\/artifactId&gt;             &lt;version&gt;3.10.0&lt;\/version&gt;             &lt;classifier&gt;jakarta&lt;\/classifier&gt;         &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0418 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0444\u0430\u0439\u043b application.yml (application.properties), \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0442\u044c Hibernate \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c L2 \u043a\u044d\u0448 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"yaml\">  jpa:     properties:       hibernate:         javax.cache:           provider: org.ehcache.jsr107.EhcacheCachingProvider           uri: ehcache.xml         cache:           use_second_level_cache: true           region.factory_class: jcache<\/code><\/pre>\n<ul>\n<li>\n<p><em>use_second_level_cache<\/em> \u2014 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043a\u044d\u0448 2 \u0443\u0440\u043e\u0432\u043d\u044f<\/p>\n<\/li>\n<li>\n<p><em>provider <\/em>\u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438) \u043a\u044d\u0448\u0430<\/p>\n<\/li>\n<li>\n<p><em>uri <\/em>\u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p><em>region.factory_class <\/em>\u2014 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c ehcache.xml. \u041f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/www.ehcache.org\/generated\/2.10.0\/html\/ehc-all\/index.html#page\/Ehcache_Documentation_Set%2Fco-hib_configuring_ehcache_settings.html%23\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>, \u043d\u0430\u043c \u0436\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u0432\u0441\u0435\u0433\u043e 3 \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0441\u0440\u043e\u043a\u0430 \u0436\u0438\u0437\u043d\u0438 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0445\u0438\u043f\u0430. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0432\u0438\u0434\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043a \u043a\u044d\u0448\u0443 MenuItemEntity:<\/p>\n<pre><code class=\"xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt; &lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"         xmlns=\"http:\/\/www.ehcache.org\/v3\"         xsi:schemaLocation=\"http:\/\/www.ehcache.org\/v3 http:\/\/www.ehcache.org\/schema\/ehcache-core-3.0.xsd\"&gt;      &lt;cache-template name=\"default\"&gt;         &lt;expiry&gt;             &lt;ttl unit=\"days\"&gt;1&lt;\/ttl&gt;         &lt;\/expiry&gt;         &lt;heap&gt;1000&lt;\/heap&gt;     &lt;\/cache-template&gt;      &lt;cache alias=\"com.example.cache_for_dummies.entity.MenuItemEntity\" uses-template=\"default\"\/&gt;  &lt;\/config&gt;<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445: \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c MenuItemEntity, \u043a\u0430\u043a \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u2014 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <em>org.hibernate.annotations.Cache:<\/em><\/p>\n<pre><code class=\"java\">@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 usage \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>READ-ONLY \u2014  \u0445\u043e\u0440\u043e\u0448\u0430 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0430\u0441\u0442\u043e \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f;<\/p>\n<\/li>\n<li>\n<p>READ-WRITE \u2014 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435;<\/p>\n<\/li>\n<li>\n<p>NONSTRICT READ-WRITE \u2014 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u0435\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u0430\u043a \u0447\u0430\u0441\u0442\u043e, \u0438 \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0434\u0432\u0443\u043c\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438;<\/p>\n<\/li>\n<li>\n<p>TRANSACTIONAL \u2014 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 JTA-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e usage, \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Cache \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"126\" width=\"126\">\n<p align=\"center\">\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"center\">\u0422\u0438\u043f<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"126\" width=\"126\">\n<p align=\"left\">includeLazy<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">boolean<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0431\u0443\u0434\u0443\u0442 \u043b\u0438 lazy \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u043a\u044d\u0448 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u0445 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e true<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"126\" width=\"126\">\n<p align=\"left\">region<\/p>\n<\/td>\n<td data-colwidth=\"123\" width=\"123\">\n<p align=\"left\">String<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0420\u0435\u0433\u0438\u043e\u043d \u043a\u044d\u0448\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0432\u0435\u043d \u043f\u043e\u043b\u043d\u043e\u043c\u0443 \u0438\u043c\u0435\u043d\u0438 \u043a\u043b\u0430\u0441\u0441\u0430<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0435 \u0436\u0435 3 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u043c\u0435\u043d\u044e:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041a \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435.<\/figcaption><\/div>\n<\/figure>\n<p>\u041a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u044b\u043b\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u043b\u0438 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u043a\u044d\u0448\u0430 \u2014 \u0443\u0440\u0430! \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c getAll, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u043c\u0435\u043d\u044e:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041e\u0439-\u0451\u0439!<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043a\u044d\u0448 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u0430\u0436\u0434\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u0432 \u0431\u0430\u0437\u0443.<\/p>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?<\/h3>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0438\u0445 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443, \u0442\u043e \u0435\u0441\u0442\u044c id. Hibernate \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0430\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u2014 \u043e\u043d \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u0445 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u043c, \u043a\u0430\u043a \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0433\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c &#171;find all&#187;, hibernate \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 all, \u0438 \u0438\u0434\u0435\u0442 \u0437\u0430 \u044d\u0442\u0438\u043c \u0432 \u0431\u0430\u0437\u0443.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c <em>\u043a\u044d\u0448 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <\/em>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e:<\/p>\n<ol>\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u043c \u043a\u044d\u0448 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 application.properties \/ application.yml: <\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"yaml\">cache:   use_query_cache: true<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0421\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c \u043a\u044d\u0448 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 ehcache.xml (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d):<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"xml\">&lt;cache alias=\"org.hibernate.cache.internal.StandardQueryCache\"        uses-template=\"default\"\/&gt;<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u041f\u043e\u043c\u0435\u0442\u0438\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u043a\u0430\u043a \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0435. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e findAll:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"java\">public interface MenuItemRepository extends JpaRepository&lt;MenuItemEntity, Long&gt; {      @Override     @QueryHints(@QueryHint(name = AvailableHints.HINT_CACHEABLE, value = \"true\"))     List&lt;MenuItemEntity&gt; findAll();  }<\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u0412 \u043b\u043e\u0433\u0430\u0445 \u0432\u0438\u0434\u0438\u043c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h3>\u041f\u0440\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438<\/h3>\n<p>\u0420\u0435\u0441\u0442\u043e\u0440\u0430\u043d \u043d\u0430\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0438\u043b\u0438\u0430\u043b\u043e\u0432 \u2014 \u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043d\u0438\u0445 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u0435\u043d\u044e \u0432 \u0440\u0435\u0441\u0442\u043e\u0440\u0430\u043d\u0430\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c, \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u0432 \u043a\u0430\u043a\u0438\u0445 \u0440\u0435\u0441\u0442\u043e\u0440\u0430\u043d\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0442\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0435 \u0431\u043b\u044e\u0434\u043e. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u043e\u0432\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c RestaurantEntity:<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"restaurants\") public class RestaurantEntity {     @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     @Column(name = \"id\", nullable = false)     private Long id;      @Column(name = \"name\", nullable = false)     private String name;      @ManyToMany     @JoinTable(name = \"restaurants_items\",             joinColumns = @JoinColumn(name = \"restaurant_id\"),             inverseJoinColumns = @JoinColumn(name = \"item_id\"))     private List&lt;MenuItemEntity&gt; menu;  }<\/code><\/pre>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c MenuItemEntity:<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"menu_items\") @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) public class MenuItemEntity {      @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     @Column(name = \"id\", nullable = false)     private Long id;      @Column(name = \"name\", nullable = false)     private String name;      @Column(name = \"calories\", nullable = false)     private Integer calories;      @Column(name = \"price\", nullable = false)     private Double price;      @ManyToMany(mappedBy = \"restaurants\")     private List&lt;RestaurantEntity&gt; restaurants;  }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0420\u0430\u0434\u0443\u0435\u043c\u0441\u044f, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"json\">{     \"id\": 2,     \"name\": \"beer\",     \"calories\": 400,     \"price\": 350.0,     \"restaurants\": [         {             \"id\": 2,             \"name\": \"Restaurant 2\"         }     ] }<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u043b\u043e\u0433\u0438 \u0438 \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e, \u0445\u043e\u0442\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 menu_items \u0431\u044b\u043b\u043e \u0432\u0441\u0435\u0433\u043e 1 \u0440\u0430\u0437, \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 restaurants_items \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<figure class=\"full-width\"><\/figure>\n<figure class=\"full-width\">\n<div><figcaption>\u0418 \u043e\u043f\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a MenuItemEntity \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445&#8230;<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043d\u0435 \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u2014 \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u0441\u0435 \u0442\u043e\u0439 \u0436\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Cache: <\/p>\n<pre><code class=\"java\">@ManyToMany(mappedBy = \"menu\") @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) private List&lt;RestaurantEntity&gt; restaurants;<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0435\u043d\u0430 \u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0432\u044f\u0437\u044c \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 restaurants_items \u0442\u043e\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u044d\u0448\u0435:) \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 One-To-Many \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f Many-To-Many \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0443\u0436\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 restaurants, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 restaurants_items. \u041d\u043e \u0438 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c, \u043f\u043e\u0432\u0435\u0441\u0438\u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @Cacheable \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c RestaurantEntity:<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"restaurants\") @Cacheable public class RestaurantEntity {<\/code><\/pre>\n<figure class=\"full-width\">\n<div><figcaption>\u0412\u0443\u0430\u043b\u044f!<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0442\u043e\u043d\u043e\u043c \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 @Cache \u0438 @Cacheable \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0434\u043b\u044f com.example.cache_for_dummies.entity.MenuItemEntity.restaurants \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u044d\u0448 \u2014 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 ehcache.xml, \u0438\u043b\u0438 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c region. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"java\">@ManyToMany(mappedBy = \"menu\") @Cache(usage = CacheConcurrencyStrategy.READ_ONLY,         region = \"com.example.cache_for_dummies.entity.MenuItemEntity\") private List&lt;RestaurantEntity&gt; restaurants;<\/code><\/pre>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u044d\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"json\">{     \"id\": 2,     \"name\": \"Restaurant 2\",     \"menu\": [         {             \"id\": 2,             \"name\": \"beer\",             \"calories\": 400,             \"price\": 350.0         },         {             \"id\": 4,             \"name\": \"ribs\",             \"calories\": 700,             \"price\": 800.0         }     ] }<\/code><\/pre>\n<figure class=\"full-width\">\n<div><figcaption>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f restaurants \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043a\u044d\u0448, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f menu_items \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 join, \u0430 \u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.<\/figcaption><\/div>\n<\/figure>\n<p>\u26a0\ufe0f \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 List&lt;MenuItemEntity&gt; menu \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @Cache, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043e\u0434\u043d\u0430\u043a\u043e \u043a\u044d\u0448 \u0441\u043e\u0437\u0434\u0430\u0441\u0442\u0441\u044f \u0438 \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 RestaurantEntity!<\/p>\n<hr\/>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u043e\u044f\u0441\u043d\u0438\u043b\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u044d\u0448\u0430 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432 Hibernate. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u043e\u0442 <a href=\"https:\/\/github.com\/Xentention\/cache_for_dummies\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\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\/articles\/833478\/\"><\/a><\/br><\/p>\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-428130","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/428130","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=428130"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/428130\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=428130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=428130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=428130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}