{"id":445360,"date":"2025-01-17T15:04:53","date_gmt":"2025-01-17T15:04:53","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=445360"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2025-01-17T15:04:53","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=445360","title":{"rendered":"<span>\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 JPA \u0438 Hibernate FetchType EAGER<\/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<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0420\u0430\u0437\u043d\u044b\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/874420\/\" rel=\"noopener noreferrer nofollow\">fetching strategies (\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f)<\/a>, \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0438\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442\u044c.<\/p>\n<p>Hibernate \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439: <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"center\"><strong>\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"left\">Join  <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f OUTER JOINED, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e SELECT  <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"left\">Select  <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 SELECT \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"left\">Subselect  <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 SELECT \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u042d\u0442\u043e\u0442 \u0440\u0435\u0436\u0438\u043c \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 <code>\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"left\">Batch    <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 SELECT. \u041f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c SELECT, \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u042d\u0442\u043e\u0442 \u0440\u0435\u0436\u0438\u043c \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 <code>\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445:<\/p>\n<ul>\n<li>\n<p>\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u0438\u043b\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, EAGER FetchType).<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, LAZY FetchType), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0432\u044f\u0437\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e SELECT.<\/p>\n<\/li>\n<\/ul>\n<p>Hibernate \u043c\u0430\u043f\u043f\u0438\u043d\u0433, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 <strong><em>\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043b\u0430\u043d \u0432\u044b\u0431\u043e\u0440\u043a\u0438<\/em><\/strong>. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043b\u0430\u043d \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f LAZY\u00a0(\u043b\u0435\u043d\u0438\u0432\u044b\u0445) \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 <code>fetch<\/code> HQL\/JPQL\/Criteria. EAGER  (\u0436\u0430\u0434\u043d\u044b\u0435) \u0441\u0432\u044f\u0437\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043a \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043b\u0430\u043d\u0443 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430.<\/p>\n<p>\u0412 Hibernate 3 \u0431\u044b\u043b\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e, \u0447\u0442\u043e LAZY \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f, \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e:<\/p>\n<blockquote>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Hibernate 3 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0438 \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u0440\u043e\u043a\u0441\u0438. \u0422\u0430\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u044e\u0442 \u0441\u043c\u044b\u0441\u043b \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/blockquote>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0439 \u0416\u0410\u0414\u041d\u041e\u0419 \u0432\u044b\u0431\u043e\u0440\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Hibernate 2. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, JPA \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u0432\u044f\u0437\u0438 &#171;\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c&#187; \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u041b\u0415\u041d\u0418\u0412\u042b\u041c\u0418, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0441\u0432\u044f\u0437\u0438 &#171;\u043a \u043e\u0434\u043d\u043e\u043c\u0443&#187; \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0416\u0410\u0414\u041d\u042b\u041c\u0418.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p align=\"center\">\u0422\u0438\u043f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p align=\"left\"><a href=\"https:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/persistence\/OneToMany.html#fetch%28%29\" rel=\"noopener noreferrer nofollow\">@OneToMany<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">LAZY<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p align=\"left\"><a href=\"https:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/persistence\/ManyToMany.html#fetch%28%29\" rel=\"noopener noreferrer nofollow\">@ManyToMany<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">LAZY<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p align=\"left\"><a href=\"https:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/persistence\/ManyToOne.html#fetch%28%29\" rel=\"noopener noreferrer nofollow\">@ManyToOne<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">EAGER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p><a href=\"https:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/persistence\/OneToOne.html#fetch%28%29\" rel=\"noopener noreferrer nofollow\">@OneToOne<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">EAGER<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u043c\u044b \u0436\u0430\u0434\u043d\u043e\u0433\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p>\u0425\u043e\u0442\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043a\u0430\u043a EAGER, \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u044f \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 Hibernate, \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.  <\/p>\n<p>EAGER \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435\u0433\u0434\u0430, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0432 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 EAGER \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 Hibernate \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/874420\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f<\/a>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d0d\/d94\/3eb\/d0dd943eb060d4793310ae166cd0c1d7.png\" width=\"601\" height=\"955\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d0d\/d94\/3eb\/d0dd943eb060d4793310ae166cd0c1d7.png\"\/><\/figure>\n<p>\u0423 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Product<\/code>\u00a0\u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438:<\/p>\n<pre><code>@ManyToOne(fetch = FetchType.EAGER) @JoinColumn(     name = \"company_id\",     nullable = false ) private Company company;   @OneToOne(     mappedBy = \"product\",     fetch = FetchType.LAZY,     cascade = CascadeType.ALL,     optional = false ) private WarehouseProductInfo warehouseProductInfo;   @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = \"importer_id\") private Importer importer;   @OneToMany(     mappedBy = \"product\",     fetch = FetchType.LAZY,     cascade = CascadeType.ALL,     orphanRemoval = true ) @OrderBy(\"index\") private Set&lt;Image&gt; images = new LinkedHashSet&lt;&gt;();<\/code><\/pre>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 <code>Company<\/code> \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a EAGER, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Hibernate \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 <code>Product<\/code>\u00a0\u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c Company.<\/p>\n<h2>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u041f\u0435\u0440\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Persistence Context API:<\/p>\n<pre><code>Product product = entityManager.find(Product.class, productId);<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>Query:{[ select     product0_.id as id1_18_1_,     product0_.code as code2_18_1_,     product0_.company_id as company_6_18_1_,     product0_.importer_id as importer7_18_1_,     product0_.name as name3_18_1_,     product0_.quantity as quantity4_18_1_,     product0_.version as version5_18_1_,     company1_.id as id1_6_0_,     company1_.name as name2_6_0_ from Product product0_ inner join Company company1_ on product0_.company_id=company1_.id where product0_.id=?][1]<\/code><\/pre>\n<p>\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f <code>Company<\/code> \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>inner join <\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 <em>M<\/em> \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439-\u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u0432 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0430 M \u0440\u0430\u0437.<\/p>\n<p>\u041a\u0430\u0436\u0434\u043e\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0449\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f, \u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0435\u0440\u044f\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u0432\u0437\u0430\u043c\u0435\u043d.<\/p>\n<h2>\u0412\u044b\u0431\u043e\u0440\u043a\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c JPQL \u0438 Criteria<\/h2>\n<p>\u043a\u043e\u0434 1:<\/p>\n<pre><code>Product product = entityManager.createQuery(     \"select p \" +     \"from Product p \" +     \"where p.id = :productId\", Product.class) .setParameter(\"productId\", productId) .getSingleResult();<\/code><\/pre>\n<p>\u043a\u043e\u0434 2:<\/p>\n<pre><code>CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery&lt;Product&gt; cq = cb.createQuery(Product.class); Root&lt;Product&gt; productRoot = cq.from(Product.class); cq.where(cb.equal(productRoot.get(\"id\"), productId)); Product product = entityManager.createQuery(cq).getSingleResult();<\/code><\/pre>\n<p>\u041e\u0431\u0430 \u0431\u043b\u043e\u043a\u0430 \u043a\u043e\u0434\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0441\u0432\u0435\u0440\u0445\u0443 \u0441\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b:<\/p>\n<pre><code>Query:{[ select     product0_.id as id1_18_,     product0_.code as code2_18_,     product0_.company_id as company_6_18_,     product0_.importer_id as importer7_18_,     product0_.name as name3_18_,     product0_.quantity as quantity4_18_,     product0_.version as version5_18_ from Product product0_ where product0_.id=?][1]}   Query:{[ select     company0_.id as id1_6_0_,     company0_.name as name2_6_0_ from Company company0_ where company0_.id=?][1]}<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 JPQL, \u0442\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 Criteria \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 select \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 EAGER \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438. \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0438\u0441\u043b\u043e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 select-\u043e\u0432, \u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u044d\u0442\u043e \u043f\u043e\u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h2>Hibernate Criteria API<\/h2>\n<p>\u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 JPA \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 2.0, \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 Criteria \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, Hibernate \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e <a href=\"https:\/\/stackoverflow.com\/questions\/27314299\/why-would-hibernates-createquery-and-createcriteria-return-a-different-number-o\/27316466#27316466\" rel=\"noopener noreferrer nofollow\">Hibernate \u0438 JPA Criteria API \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443<\/a> \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>\u0412 Hibernate Criteria, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>Product product = (Product) session     .createCriteria(Product.class)     .add(Restrictions.eq(\"id\", productId))     .uniqueResult();<\/code><\/pre>\n<p>\u0421\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u043d\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u044b\u043b \u0431\u044b \u0442\u0430\u043a\u0438\u043c:<\/p>\n<pre><code>Query:{[ select     this_.id as id1_3_1_,     this_.code as code2_3_1_,     this_.company_id as company_6_3_1_,     this_.importer_id as importer7_3_1_,     this_.name as name3_3_1_,     this_.quantity as quantity4_3_1_,     this_.version as version5_3_1_,     hibernatea2_.id as id1_0_0_,     hibernatea2_.name as name2_0_0_ from Product this_ inner join Company hibernatea2_ on this_.company_id=hibernatea2_.id where this_.id=?][1]}<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>join fetch<\/code> \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<h2>Hibernate Criteria \u0438 EAGER \u043a\u043e\u043b\u0435\u043a\u0446\u0438\u0438<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <code>Image<\/code> \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043d\u0430 EAGER:<\/p>\n<pre><code>@OneToMany(     mappedBy = \"product\",     fetch = FetchType.EAGER,     cascade = CascadeType.ALL,     orphanRemoval = true ) @OrderBy(\"index\") private Set&lt;Image&gt; images = new LinkedHashSet&lt;&gt;();<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>Query:{[ select     this_.id as id1_3_2_,     this_.code as code2_3_2_,     this_.company_id as company_6_3_2_,     this_.importer_id as importer7_3_2_,     this_.name as name3_3_2_,     this_.quantity as quantity4_3_2_,     this_.version as version5_3_2_,     hibernatea2_.id as id1_0_0_,     hibernatea2_.name as name2_0_0_,     images3_.product_id as product_4_3_4_,     images3_.id as id1_1_4_,     images3_.id as id1_1_1_,     images3_.index as index2_1_1_,     images3_.name as name3_1_1_,     images3_.product_id as product_4_1_1_ from Product this_ inner join Company hibernatea2_ on this_.company_id=hibernatea2_.id left outer join Image images3_ on this_.id=images3_.product_id where this_.id=? order by images3_.index][1]}<\/code><\/pre>\n<p>Hibernate Criteria \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u044e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u0418\u0437-\u0437\u0430 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>\u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 (\u0432\u0441\u0435 \u043e\u043d\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u041f\u0435\u0440\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438):<\/p>\n<pre><code>product.setName(\"TV\"); product.setCompany(company);   Image frontImage = new Image(); frontImage.setName(\"front image\"); frontImage.setIndex(0);   Image sideImage = new Image(); sideImage.setName(\"side image\"); sideImage.setIndex(1);   product.addImage(frontImage); product.addImage(sideImage);   List products = session     .createCriteria(Product.class)     .add(Restrictions.eq(\"id\", productId))     .list();       assertEquals(2, products.size()); assertSame(products.get(0), products.get(1));<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 image, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0432\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Product, \u043e\u0431\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043a\u044d\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c Hibernate Criteria, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b:<\/p>\n<pre><code>List products = session     .createCriteria(Product.class)     .add(Restrictions.eq(\"id\", productId))     .setResultTransformer(         CriteriaSpecification.DISTINCT_ROOT_ENTITY     )     .list();   assertEquals(1, products.size());<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 EAGER &#8212; \u044d\u0442\u043e code smell. \u042d\u0442\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043d\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0435 \u043f\u043e\u0442\u0435\u0440\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u0420\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <\/p>\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043b\u0430\u043d \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e LAZY \u0441\u0432\u044f\u0437\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0412 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441\u043e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0435\u0439 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043b\u0430\u043d\u044b \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043d\u0430 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u0435.  <\/p>\n<\/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\/874484\/\"> https:\/\/habr.com\/ru\/articles\/874484\/<\/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<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0420\u0430\u0437\u043d\u044b\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/874420\/\" rel=\"noopener noreferrer nofollow\">fetching strategies (\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f)<\/a>, \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0438\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442\u044c.<\/p>\n<p>Hibernate \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439: <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"center\"><strong>\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"left\">Join  <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f OUTER JOINED, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e SELECT  <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"left\">Select  <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 SELECT \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"left\">Subselect  <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 SELECT \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u042d\u0442\u043e\u0442 \u0440\u0435\u0436\u0438\u043c \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 <code>\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"133\" width=\"133\">\n<p align=\"left\">Batch    <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 SELECT. \u041f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c SELECT, \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u042d\u0442\u043e\u0442 \u0440\u0435\u0436\u0438\u043c \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 <code>\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445:<\/p>\n<ul>\n<li>\n<p>\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u0438\u043b\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, EAGER FetchType).<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, LAZY FetchType), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0432\u044f\u0437\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e SELECT.<\/p>\n<\/li>\n<\/ul>\n<p>Hibernate \u043c\u0430\u043f\u043f\u0438\u043d\u0433, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 <strong><em>\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043b\u0430\u043d \u0432\u044b\u0431\u043e\u0440\u043a\u0438<\/em><\/strong>. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043b\u0430\u043d \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f LAZY\u00a0(\u043b\u0435\u043d\u0438\u0432\u044b\u0445) \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 <code>fetch<\/code> HQL\/JPQL\/Criteria. EAGER  (\u0436\u0430\u0434\u043d\u044b\u0435) \u0441\u0432\u044f\u0437\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043a \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043b\u0430\u043d\u0443 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430.<\/p>\n<p>\u0412 Hibernate 3 \u0431\u044b\u043b\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e, \u0447\u0442\u043e LAZY \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f, \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e:<\/p>\n<blockquote>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Hibernate 3 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0438 \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u0440\u043e\u043a\u0441\u0438. \u0422\u0430\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u044e\u0442 \u0441\u043c\u044b\u0441\u043b \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/blockquote>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0439 \u0416\u0410\u0414\u041d\u041e\u0419 \u0432\u044b\u0431\u043e\u0440\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Hibernate 2. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, JPA \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u0432\u044f\u0437\u0438 &#171;\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c&#187; \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u041b\u0415\u041d\u0418\u0412\u042b\u041c\u0418, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0441\u0432\u044f\u0437\u0438 &#171;\u043a \u043e\u0434\u043d\u043e\u043c\u0443&#187; \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0416\u0410\u0414\u041d\u042b\u041c\u0418.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p align=\"center\">\u0422\u0438\u043f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438<\/p>\n<\/td>\n<td>\n<p align=\"center\">\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p align=\"left\"><a href=\"https:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/persistence\/OneToMany.html#fetch%28%29\" rel=\"noopener noreferrer nofollow\">@OneToMany<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">LAZY<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p align=\"left\"><a href=\"https:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/persistence\/ManyToMany.html#fetch%28%29\" rel=\"noopener noreferrer nofollow\">@ManyToMany<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">LAZY<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p align=\"left\"><a href=\"https:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/persistence\/ManyToOne.html#fetch%28%29\" rel=\"noopener noreferrer nofollow\">@ManyToOne<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">EAGER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"351\" width=\"351\">\n<p><a href=\"https:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/persistence\/OneToOne.html#fetch%28%29\" rel=\"noopener noreferrer nofollow\">@OneToOne<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">EAGER<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u043c\u044b \u0436\u0430\u0434\u043d\u043e\u0433\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p>\u0425\u043e\u0442\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u043a\u0430\u043a EAGER, \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u044f \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 Hibernate, \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.  <\/p>\n<p>EAGER \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435\u0433\u0434\u0430, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0432 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 EAGER \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 Hibernate \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/874420\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f<\/a>:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0423 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Product<\/code>\u00a0\u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438:<\/p>\n<pre><code>@ManyToOne(fetch = FetchType.EAGER) @JoinColumn(     name = \"company_id\",     nullable = false ) private Company company;   @OneToOne(     mappedBy = \"product\",     fetch = FetchType.LAZY,     cascade = CascadeType.ALL,     optional = false ) private WarehouseProductInfo warehouseProductInfo;   @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = \"importer_id\") private Importer importer;   @OneToMany(     mappedBy = \"product\",     fetch = FetchType.LAZY,     cascade = CascadeType.ALL,     orphanRemoval = true ) @OrderBy(\"index\") private Set&lt;Image&gt; images = new LinkedHashSet&lt;&gt;();<\/code><\/pre>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 <code>Company<\/code> \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a EAGER, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Hibernate \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 <code>Product<\/code>\u00a0\u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c Company.<\/p>\n<h2>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u041f\u0435\u0440\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Persistence Context API:<\/p>\n<pre><code>Product product = entityManager.find(Product.class, productId);<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>Query:{[ select     product0_.id as id1_18_1_,     product0_.code as code2_18_1_,     product0_.company_id as company_6_18_1_,     product0_.importer_id as importer7_18_1_,     product0_.name as name3_18_1_,     product0_.quantity as quantity4_18_1_,     product0_.version as version5_18_1_,     company1_.id as id1_6_0_,     company1_.name as name2_6_0_ from Product product0_ inner join Company company1_ on product0_.company_id=company1_.id where product0_.id=?][1]<\/code><\/pre>\n<p>\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f <code>Company<\/code> \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>inner join <\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 <em>M<\/em> \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439-\u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u0432 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0430 M \u0440\u0430\u0437.<\/p>\n<p>\u041a\u0430\u0436\u0434\u043e\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0449\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f, \u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0435\u0440\u044f\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u0432\u0437\u0430\u043c\u0435\u043d.<\/p>\n<h2>\u0412\u044b\u0431\u043e\u0440\u043a\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c JPQL \u0438 Criteria<\/h2>\n<p>\u043a\u043e\u0434 1:<\/p>\n<pre><code>Product product = entityManager.createQuery(     \"select p \" +     \"from Product p \" +     \"where p.id = :productId\", Product.class) .setParameter(\"productId\", productId) .getSingleResult();<\/code><\/pre>\n<p>\u043a\u043e\u0434 2:<\/p>\n<pre><code>CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery&lt;Product&gt; cq = cb.createQuery(Product.class); Root&lt;Product&gt; productRoot = cq.from(Product.class); cq.where(cb.equal(productRoot.get(\"id\"), productId)); Product product = entityManager.createQuery(cq).getSingleResult();<\/code><\/pre>\n<p>\u041e\u0431\u0430 \u0431\u043b\u043e\u043a\u0430 \u043a\u043e\u0434\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0441\u0432\u0435\u0440\u0445\u0443 \u0441\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b:<\/p>\n<pre><code>Query:{[ select     product0_.id as id1_18_,     product0_.code as code2_18_,     product0_.company_id as company_6_18_,     product0_.importer_id as importer7_18_,     product0_.name as name3_18_,     product0_.quantity as quantity4_18_,     product0_.version as version5_18_ from Product product0_ where product0_.id=?][1]}   Query:{[ select     company0_.id as id1_6_0_,     company0_.name as name2_6_0_ from Company company0_ where company0_.id=?][1]}<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 JPQL, \u0442\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 Criteria \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 select \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 EAGER \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438. \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0438\u0441\u043b\u043e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 select-\u043e\u0432, \u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u044d\u0442\u043e \u043f\u043e\u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h2>Hibernate Criteria API<\/h2>\n<p>\u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 JPA \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 2.0, \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 Criteria \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, Hibernate \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e <a href=\"https:\/\/stackoverflow.com\/questions\/27314299\/why-would-hibernates-createquery-and-createcriteria-return-a-different-number-o\/27316466#27316466\" rel=\"noopener noreferrer nofollow\">Hibernate \u0438 JPA Criteria API \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443<\/a> \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>\u0412 Hibernate Criteria, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>Product product = (Product) session     .createCriteria(Product.class)     .add(Restrictions.eq(\"id\", productId))     .uniqueResult();<\/code><\/pre>\n<p>\u0421\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u043d\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u044b\u043b \u0431\u044b \u0442\u0430\u043a\u0438\u043c:<\/p>\n<pre><code>Query:{[ select     this_.id as id1_3_1_,     this_.code as code2_3_1_,     this_.company_id as company_6_3_1_,     this_.importer_id as importer7_3_1_,     this_.name as name3_3_1_,     this_.quantity as quantity4_3_1_,     this_.version as version5_3_1_,     hibernatea2_.id as id1_0_0_,     hibernatea2_.name as name2_0_0_ from Product this_ inner join Company hibernatea2_ on this_.company_id=hibernatea2_.id where this_.id=?][1]}<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>join fetch<\/code> \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<h2>Hibernate Criteria \u0438 EAGER \u043a\u043e\u043b\u0435\u043a\u0446\u0438\u0438<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <code>Image<\/code> \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043d\u0430 EAGER:<\/p>\n<pre><code>@OneToMany(     mappedBy = \"product\",     fetch = FetchType.EAGER,     cascade = CascadeType.ALL,     orphanRemoval = true ) @OrderBy(\"index\") private Set&lt;Image&gt; images = new LinkedHashSet&lt;&gt;();<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>Query:{[ select     this_.id as id1_3_2_,     this_.code as code2_3_2_,     this_.company_id as company_6_3_2_,     this_.importer_id as importer7_3_2_,     this_.name as name3_3_2_,     this_.quantity as quantity4_3_2_,     this_.version as version5_3_2_,     hibernatea2_.id as id1_0_0_,     hibernatea2_.name as name2_0_0_,     images3_.product_id as product_4_3_4_,     images3_.id as id1_1_4_,     images3_.id as id1_1_1_,     images3_.index as index2_1_1_,     images3_.name as name3_1_1_,     images3_.product_id as product_4_1_1_ from Product this_ inner join Company hibernatea2_ on this_.company_id=hibernatea2_.id left outer join Image images3_ on this_.id=images3_.product_id where this_.id=? order by images3_.index][1]}<\/code><\/pre>\n<p>Hibernate Criteria \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u044e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u0418\u0437-\u0437\u0430 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>\u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 (\u0432\u0441\u0435 \u043e\u043d\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u041f\u0435\u0440\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438):<\/p>\n<pre><code>product.setName(\"TV\"); product.setCompany(company);   Image frontImage = new Image(); frontImage.setName(\"front image\"); frontImage.setIndex(0);   Image sideImage = new Image(); sideImage.setName(\"side image\"); sideImage.setIndex(1);   product.addImage(frontImage); product.addImage(sideImage);   List products = session     .createCriteria(Product.class)     .add(Restrictions.eq(\"id\", productId))     .list();       assertEquals(2, products.size()); assertSame(products.get(0), products.get(1));<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 image, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0432\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Product, \u043e\u0431\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043a\u044d\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c Hibernate Criteria, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b:<\/p>\n<pre><code>List products = session     .createCriteria(Product.class)     .add(Restrictions.eq(\"id\", productId))     .setResultTransformer(         CriteriaSpecification.DISTINCT_ROOT_ENTITY     )     .list();   assertEquals(1, products.size());<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 EAGER &#8212; \u044d\u0442\u043e code smell. \u042d\u0442\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043d\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0435 \u043f\u043e\u0442\u0435\u0440\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u0420\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <\/p>\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043b\u0430\u043d \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e LAZY \u0441\u0432\u044f\u0437\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0412 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441\u043e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0435\u0439 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043b\u0430\u043d\u044b \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043d\u0430 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u0435.  <\/p>\n<\/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\/874484\/\"> https:\/\/habr.com\/ru\/articles\/874484\/<\/a><br \/><\/br><\/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-445360","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/445360","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=445360"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/445360\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=445360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=445360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=445360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}