{"id":429713,"date":"2024-08-21T21:02:48","date_gmt":"2024-08-21T21:02:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=429713"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=429713","title":{"rendered":"<span>JPA Entity. \u0417\u0430\u0433\u0440\u0443\u0437\u0438 \u043c\u0435\u043d\u044f \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e<\/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>JPA \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0435 \u0437\u0430 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435\u043c. Spring Data JPA \u0438 Hibernate \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u0435\u0431\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.\u00a0<\/p>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 <a href=\"https:\/\/t.me\/+QmrKn0wA8CdkNjAy\">Spring \u0410\u0439\u041e<\/a> \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0430 \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0432 Spring Data JPA \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0430 \u0438\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 corner-\u043a\u0435\u0439\u0441\u044b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 Hibernate \u0432 Spring \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445:<\/p>\n<ul>\n<li>\n<p>Spring Data JPA<\/p>\n<\/li>\n<li>\n<p>EntityManager<\/p>\n<\/li>\n<li>\n<p>Criteria API<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 <a href=\"https:\/\/github.com\/jakartaee\/data\">Jakarta Data<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b\u0448\u043b\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f 1.0.0. \u0420\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u043a\u043e\u043f\u0438\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0439.  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/35e\/8d6\/bd5\/35e8d6bd500bb63a86a1fbd3608387e8.png\" width=\"780\" height=\"444\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/35e\/8d6\/bd5\/35e8d6bd500bb63a86a1fbd3608387e8.png\"\/><\/figure>\n<h3>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043b\u0438 \u044d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0445\u043e\u043b\u0438\u0432\u0430\u0440\u0430 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 Telegram-\u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u043f\u0440\u043e Java \u043d\u0430 \u0442\u0435\u043c\u0443 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043b\u043e\u0445 JPA \u0438 Hibernate \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u043a \u043e\u043d \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0433\u0440\u0443\u0437\u0438\u0442\u0441\u044f \u043b\u0438\u0448\u043d\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0442\u0430\u0442\u044c \u043d\u0430 \u0437\u0430\u0449\u0438\u0442\u0443 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u0441\u0442\u044d\u043a\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u0432 \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435 \u043d\u0430 Stackoverflow. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0442\u0435\u0433\u0443 <code>[spring-data-jpa]<\/code> \u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438. \u041c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 <a href=\"https:\/\/stackoverflow.com\/questions\/22007341\/spring-jpa-selecting-specific-columns\">Spring JPA selecting specific columns<\/a>  \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0448\u0435\u0441\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<br \/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0435\u043c\u0441\u044f \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0448\u0438\u0440\u043e\u043a\u043e: \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u043a\u0443\u043d\u0435\u043c\u0441\u044f \u0438 \u0432 \u043c\u0438\u0440 JPA-\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439.<\/p>\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430<\/h3>\n<p>\u0412 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\">\u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/a> \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5a6\/cc9\/76c\/5a6cc976c104ca2209aee23b0911f222.png\" width=\"1788\" height=\"762\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5a6\/cc9\/76c\/5a6cc976c104ca2209aee23b0911f222.png\"\/><\/figure>\n<p>\u041d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u043e\u043b\u0435\u0439 + ToOne (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442 author, \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c Post) \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u043f\u0440\u0438\u0447\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u043d\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443, \u0442.\u0435. contains with ignore case. \u0418\u0442\u043e\u0433\u043e \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c <code>Post: id, slug, title; User(author): id, username<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/tree\/main\/src\/test\/java\/io\/amplicode\/jpa\/repository\">\u0442\u0435\u0441\u0442\u0430\u0445<\/a>, \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u0438\u0434\u043d\u044b \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438: \u043b\u043e\u0433, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u0441\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u043b\u0430\u043c\u0438 Hibernate.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 <code>Post<\/code>, \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0432 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u044f \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0432 \u0430\u0432\u0442\u043e\u0440\u043e\u0432. \u0421\u0435\u0440\u0432\u0438\u0441 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/blob\/main\/src\/test\/java\/io\/amplicode\/jpa\/InitTestDataService.java\">InitTestDataService<\/a>.<\/p>\n<h3>toOne<\/h3>\n<p>\u0412\u0441\u0435\u0433\u043e \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d 21 \u0441\u043f\u043e\u0441\u043e\u0431 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u042d\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u0435\u0431\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<ul>\n<li>\n<p>Spring Data Repository derived-methods<\/p>\n<\/li>\n<li>\n<p>Spring Data Repository query-methods<\/p>\n<\/li>\n<li>\n<p>Entity Manager<\/p>\n<\/li>\n<li>\n<p>Criteria API<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 &#8212; <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/blob\/main\/src\/test\/java\/io\/amplicode\/jpa\/repository\/ToOneTest.java\">ToOneTest<\/a>.<\/p>\n<h3>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0432\u043d\u0435\u0441\u0442\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u044f\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0448\u0438\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u043c. <code>Derived<\/code> \u043c\u0435\u0442\u043e\u0434\u044b \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0445 \u0438\u043c\u0435\u043d, \u0442.\u0435. \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/docs.spring.io\/spring-data\/commons\/reference\/repositories\/query-methods.html\">@Query<\/a>. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u044f\u0432\u043d\u043e, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0443 \u043d\u0430\u0441 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c,\u00a0\u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 &#8212; \u044d\u0442\u043e <strong>projection<\/strong>.<\/p>\n<p>\u0421\u0430\u043c\u0438 \u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u0431\u044b\u0432\u0430\u044e\u0442 \u0434\u0432\u0443\u0445 \u0432\u0438\u0434\u043e\u0432: <strong>\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u0445 <\/strong>(Interface-based Projections) \u0438 <strong>\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 <\/strong>(Class-based Projections). <strong>Interface-based Projections <\/strong>\u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0435.<\/p>\n<p>\u0412 <a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/reference\/repositories\/projections.html#projections.interfaces.closed\">\u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0445<\/a> \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f\u0445 \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044f\u0432\u043d\u043e:<\/p>\n<pre><code class=\"java\">interface NamesOnly {   String getFirstname();   String getLastname(); }<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 <a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/reference\/repositories\/projections.html#projections.interfaces.open\">\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439<\/a> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 SpEL \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"java\">interface NamesOnly {       @Value(\"#{target.firstname + ' ' + target.lastname}\")     String getFullName(); }  <\/code><\/pre>\n<p>\u0418\u0445 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u0442.\u043a. \u0432 <a href=\"https:\/\/docs.spring.io\/spring-data\/cassandra\/reference\/repositories\/projections.html#:~:text=Spring%20Data%20cannot%20apply%20query%20execution%20optimizations%20in%20this%20case%2C%20because%20the%20SpEL%20expression%20could%20use%20any%20attribute%20of%20the%20aggregate%20root.\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044f\u0432\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e<\/a>, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0438\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<blockquote>\n<p>Spring Data cannot apply query execution optimizations in this case, because the SpEL expression could use any  attribute of the aggregate root.<\/p>\n<\/blockquote>\n<p>\u0414\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 <strong>ToOne<\/strong>-\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0441 <strong>flatten<\/strong> (\u043f\u043b\u043e\u0441\u043a\u0438\u043c\u0438) \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u0441 <strong>nested<\/strong> (\u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c) \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 <strong>Tuple<\/strong> \u0438 <strong>Map<\/strong>. <\/p>\n<p>\u0414\u043b\u044f <strong>ToMany<\/strong>  \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043f\u043b\u043e\u0441\u043a\u0438\u043c\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e n*m. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0448 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438 \u0434\u043b\u044f ToOne, \u0438 \u0434\u043b\u044f ToMany, \u043e\u0434\u043d\u0430\u043a\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 ToMany<strong> <\/strong>\u0432\u044b\u0433\u0440\u0443\u0437\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u043b\u044f ToOne, \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0438 \u0434\u043b\u044f ToMany, \u043e\u0434\u043d\u0430\u043a\u043e Hibernate \u043d\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043c\u0430\u043f\u0438\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0430 DTO\/Projection, \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0447\u0435\u043c Hibernate \u0432 \u0441\u0438\u043b\u0430\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e HQL, \u0438 \u0434\u043b\u044f \u043a\u0435\u0439\u0441\u0430 \u0441 ToMany \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 n*m. \u0418\u043d\u0430\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043a\u0440\u043e\u043c\u0435 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u043c\u0430\u043f\u0438\u043d\u0433\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0441\u0445\u043b\u043e\u043f\u044b\u0432\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u0415\u0441\u043b\u0438 \u044d\u0442\u0430 \u0442\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430, \u043c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u043f\u0440\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u0441 ToMany-\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f\u043c\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\">\u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/a> \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/blob\/main\/src\/test\/java\/io\/amplicode\/jpa\/repository\/ToManyTest.java\">ToManyTest<\/a>. <\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u0434\u0430\u043b\u0435\u0435, \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0438 \u0434\u043b\u044f <strong>Embbeded<\/strong>-\u043a\u0435\u0439\u0441\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430<\/p>\n<h3>Derived-methods<\/h3>\n<h4>Interface-based flat projection<\/h4>\n<p>\u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u0431\u0443\u0434\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u043a \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439.<\/p>\n<p>\u041e\u0431\u044a\u044f\u0432\u0438\u043c \u0432 \u043d\u0430\u0448\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"java\">public interface PostRepository extends JpaRepository&lt;Post, Long&gt; {   &lt;T&gt; List&lt;T&gt; findAllByTitleContainsIgnoreCase(String title, Class&lt;T&gt; projection); }<\/code><\/pre>\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u0446\u0435\u043b\u044f\u0445 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 <a href=\"https:\/\/www.baeldung.com\/spring-data-jpa-projections#dynamic-projections\">\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e<\/a>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<br \/>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\"> public interface PostWithAuthorFlat {       Long getId();       String getSlug();       String getTitle();       Long getAuthorId();       String getAuthorUsername();   }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u0442\u0435\u0441\u0442. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0434\u0435\u0431\u0430\u0433\u043e\u043c. \u0421\u0442\u0430\u0432\u0438\u043c breakpoint \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7ec\/4f3\/22a\/7ec4f322a5dc3d29bfc8063ca8781ab2.png\" width=\"1958\" height=\"490\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ec\/4f3\/22a\/7ec4f322a5dc3d29bfc8063ca8781ab2.png\"\/><\/figure>\n<p>\u0417\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u043c \u0437\u0432\u0435\u043d\u043e\u043c \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 TupleBackedMap, \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 Tuple \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u043d\u0430\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 breakpoint \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 TupleBackedMap <code>(org.springframework.data.jpa.repository.query.AbstractJpaQuery.TupleConverter.TupleBackedMap)<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e9f\/6a4\/6eb\/e9f6a46eb3593c4f697fb9d969342921.png\" width=\"1868\" height=\"1038\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e9f\/6a4\/6eb\/e9f6a46eb3593c4f697fb9d969342921.png\"\/><\/figure>\n<p> \u0418 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3b1\/583\/39a\/3b158339a53f896ee5054a88059a359d.png\" width=\"1150\" height=\"666\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b1\/583\/39a\/3b158339a53f896ee5054a88059a359d.png\"\/><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043a\u0441\u0438 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <code>invoke<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 <code>MapAccessingMethodInterceptor<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e22\/093\/332\/e220933326bb1a1f4bafb5cdc2970990.png\" width=\"1980\" height=\"1204\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e22\/093\/332\/e220933326bb1a1f4bafb5cdc2970990.png\"\/><\/figure>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Accessor<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0430\u043c\u043e\u043c\u0443 <code>propertyName<\/code>. \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u0430 \u0432 <code>TupleBackedMap<\/code>. \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0438\u0437 \u0432\u0441\u0435\u043c\u0438 \u043d\u0430\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>Tuple<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/114\/4a5\/a4b\/1144a5a4b4209a20809c180ffcfba573.png\" width=\"1738\" height=\"1019\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/114\/4a5\/a4b\/1144a5a4b4209a20809c180ffcfba573.png\"\/><\/figure>\n<p>\u0421\u0430\u043c \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 <code>Tuple<\/code> \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043b\u044e\u0447\u0443 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<\/p>\n<p>\u0412\u0441\u044e \u0441\u0445\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a:<br \/>\u041f\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0435\u0439 \u043b\u0435\u0436\u0438\u0442 \u043f\u0440\u043e\u043a\u0441\u0438, \u0432 \u043f\u0440\u043e\u043a\u0441\u0438 &#8212; \u043f\u0440\u043e\u043a\u0441\u0438, \u0432 \u043f\u0440\u043e\u043a\u0441\u0438 \u043b\u0435\u0436\u0438\u0442 \u043d\u0435\u043a\u0438\u0439 target-\u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c <code>TupleBackedMap<\/code>.<\/p>\n<p>\u0418\u043b\u0438 \u0442\u0430\u043a:<br \/> <em>\u00ab\u041d\u0430 \u043c\u043e\u0440\u0435 \u043d\u0430 \u043e\u043a\u0435\u0430\u043d\u0435 \u0435\u0441\u0442\u044c \u043e\u0441\u0442\u0440\u043e\u0432, \u043d\u0430 \u0442\u043e\u043c \u043e\u0441\u0442\u0440\u043e\u0432\u0435 \u0434\u0443\u0431 \u0441\u0442\u043e\u0438\u0442, \u043f\u043e\u0434 \u0434\u0443\u0431\u043e\u043c \u0441\u0443\u043d\u0434\u0443\u043a \u0437\u0430\u0440\u044b\u0442, \u0432 \u0441\u0443\u043d\u0434\u0443\u043a\u0435 \u2014 \u0437\u0430\u044f\u0446, \u0432 \u0437\u0430\u0439\u0446\u0435 \u2014 \u0443\u0442\u043a\u0430, \u0432 \u0443\u0442\u043a\u0435 \u2014 \u044f\u0439\u0446\u043e\u00bb<\/em>\u00a0\u0432 \u044f\u0439\u0446\u0435 \u0438\u0433\u043b\u0430 \u2014 \u0441\u043c\u0435\u0440\u0442\u044c \u041a\u043e\u0449\u0435\u044f!<\/p>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e Spring \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u043c\u0430\u043f\u043f\u0438\u0442 <code>Tuple<\/code> \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e. \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0438, \u0432\u0435\u0434\u044c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         p1_0.author_id,         a1_0.username      from         posts p1_0      left join         users a1_0              on a1_0.id=p1_0.author_id      where         upper(p1_0.title) like upper(?) escape '\\'<\/code><\/pre>\n<h4>Interface-based nested interface projections<\/h4>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u043e\u0433\u043b\u043e \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438, \u0438\u043c\u0435\u044e\u0449\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e, \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431 \u0430\u0432\u0442\u043e\u0440\u0435 \u043f\u043e\u0441\u0442\u0430. \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 <strong>nested<\/strong> \u043a\u0435\u0439\u0441.<\/p>\n<pre><code class=\"java\">public interface PostWithAuthorNested {       Long getId();       String getSlug();       String getTitle();       UserPresentation getAuthor();   }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c <code>id<\/code>, <code>slug<\/code>, <code>title<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u044b \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u0447\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u043d\u0430\u0448\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0438 \u0434\u0430\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 <a href=\"https:\/\/github.com\/spring-projects\/spring-data-jpa\/issues\/3352\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442<\/a>. <\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>PostWithAuthorNested<\/code> \u044d\u0442\u043e \u0432\u0441\u0435 \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u043e\u043a\u0441\u0438 \u0432\u043e\u043a\u0440\u0443\u0433 <code>TupleBackedMap<\/code>, \u0430 \u0432\u043e\u0442 \u0441\u0430\u043c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>UserPresentation<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043a\u0441\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u043e\u043a\u0440\u0443\u0433 \u0441\u0430\u043c\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>User<\/code>:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         a1_0.id,         a1_0.bio,         a1_0.email,         a1_0.image,         a1_0.password,         a1_0.token,         a1_0.username      from         posts p1_0      left join         users a1_0              on a1_0.id=p1_0.author_id      where         upper(p1_0.title) like upper(?) escape '\\'<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433\u0438: \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u043d\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0435 \u0440\u0435\u0448\u0430\u0435\u0442.<\/p>\n<h4>Class-based flat projections<\/h4>\n<p>\u0418\u0434\u0435\u043c \u0434\u0430\u043b\u0435\u0435 \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0435 \u043f\u043e\u043b\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e <code>Record<\/code>-\u043a\u043b\u0430\u0441\u0441\u0430 (\u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c)<\/p>\n<pre><code class=\"java\">public record PostWithAuthorFlatDto(Long id,                                       String slug,                                       String title,                                       Long authorId,                                       String authorUsername) {   }<\/code><\/pre>\n<p>\u0421\u0430\u043c \u0442\u0435\u0441\u0442:<\/p>\n<pre><code class=\"java\">@Test   void derivedMethodClassFlatPrj() {       var posts = postRepository.findAllByTitleContainsIgnoreCase(       \"spring\",       PostWithAuthorFlatDto.class     );       assertEquals(1, posts.size());       var postFirst = posts.getFirst();       assertEquals(POST1_SLUG, postFirst.slug());       assertEquals(POST1_AUTHOR_NAME, postFirst.authorUsername());   }<\/code><\/pre>\n<p><strong>Spring Data JPA<\/strong> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 result type \u0432 Hibernate, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043c\u0430\u043f\u0438\u043d\u0433. \u041d\u0430 \u043f\u043b\u0435\u0447\u0430\u0445 Spring&#8217;\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <strong>JPQL<\/strong> \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430\u0441 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         p1_0.author_id,         a1_0.username      from         posts p1_0      left join         users a1_0              on a1_0.id=p1_0.author_id      where         upper(p1_0.title) like upper(?) escape '\\'<\/code><\/pre>\n<h4>Class-based nested dto projections<\/h4>\n<p>\u0418\u0434\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0442\u0435\u043c\u043f\u043e\u043c, \u043e\u0434\u043d\u0430\u043a\u043e \u0441\u0442\u043e\u0438\u043b\u043e \u0431\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0435, \u043d\u0435\u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f\u043c\u0438. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u043a\u043e\u0439 record \u043a\u043b\u0430\u0441\u0441 \u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 DTO-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"java\">public record PostWithAuthorNestedDto(Long id,                                         String slug,                                         String title,                                         UserPresentationDto author) {   }<\/code><\/pre>\n<p>\u0412\u0440\u043e\u0434\u0435, \u0432\u0441\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 &#171;\u0432\u0437\u043b\u0435\u0442\u0435\u0442\u044c&#187; \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code class=\"java\">Cannot set field 'author' to instantiate 'io.spring.jpa.projection.PostWithAuthorNestedDto'<\/code><\/pre>\n<p>\u041e \u0447\u0435\u043c \u043d\u0430\u0441 <a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/reference\/repositories\/projections.html#projections.dtos\">\u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u043b\u0438<\/a>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/751\/e8b\/0a2\/751e8b0a2f3d8c3c326de3544dbc7383.png\" width=\"1588\" height=\"952\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/751\/e8b\/0a2\/751e8b0a2f3d8c3c326de3544dbc7383.png\"\/><\/figure>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Hibernate, Spring Data \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u044f.<\/p>\n<h3>Class-based nested entity projections<\/h3>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u043b\u044f record \u0446\u0435\u043b\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043a\u043e\u043f\u0438\u043b\u043a\u0443 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u0435\u0439\u0441. \u041d\u0435 \u043d\u0430\u0448 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043f\u0440\u043e \u044d\u0442\u043e, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u043e\u043b\u0435\u0437\u043d\u043e:<\/p>\n<pre><code class=\"java\">public record PostWithAuthorEntity(Long id,                                      String slug,                                      String title,                                      User author) {   }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         a1_0.id,         a1_0.bio,         a1_0.email,         a1_0.image,         a1_0.password,         a1_0.token,         a1_0.username      from         posts p1_0      left join         users a1_0              on a1_0.id=p1_0.author_id      where         upper(p1_0.title) like upper(?) escape '\\'<\/code><\/pre>\n<h3>Query-methods<\/h3>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u044f\u0432\u043d\u043e \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u0442\u044c, \u0442.\u0435. \u043a <code>Query<\/code>-\u043c\u0435\u0442\u043e\u0434\u0430\u043c. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0440\u0435\u0448\u0430\u0435\u043c \u043e\u0434\u043d\u0443 \u043d\u0435\u043c\u0430\u043b\u043e\u0432\u0430\u0436\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 &#8212; \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c. \u0412 \u043d\u0430\u0448\u0435\u0439 \u0437\u043e\u043d\u0435 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043f\u043f\u0438\u043d\u0433.<\/p>\n<h4>Interface-based flat projections<\/h4>\n<p>Spring \u0431\u043e\u0433\u0430\u0442 \u0441\u0432\u043e\u0438\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u043e\u043d, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c <code>JPQL<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438 \u0432\u043e\u0432\u0441\u0435 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>TupleBackedMap<\/code>.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u0442\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 <code>JPQL<\/code> \u0437\u0430\u043f\u0440\u043e\u0441, \u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"java\">@Query(\"\"\"             select  a.id as id,                     a.slug as slug,                     a.title as title,                     a.author.id as authorId,                     a.author.username as authorUsername             from Post a             where lower(a.title) like lower(concat('%', ?1, '%'))\"\"\") List&lt;PostWithAuthorFlat&gt; findAllPostWithAuthorFlat(String title);<\/code><\/pre>\n<p>\u0421\u0430\u043c\u0430 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"java\">public interface PostWithAuthorFlat {       Long getId();       String getSlug();       String getTitle();       Long getAuthorId();       String getAuthorUsername();   }<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <code>JPQL<\/code>-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044e \u0430\u043b\u0438\u0430\u0441\u043e\u0432: \u043e\u043d\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435, \u043a\u0430\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438, \u0438\u043d\u0430\u0447\u0435 \u043c\u0430\u0433\u0438\u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442. \u041a\u0441\u0442\u0430\u0442\u0438, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043f\u043e\u0434 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u043b\u0435\u0436\u0438\u0442 \u0432\u0441\u0435 \u0442\u0430 \u0436\u0435 \u043f\u0440\u043e\u043a\u0441\u0438 \u0441 <code>TupleBackedMap<\/code>.<\/p>\n<p>\u0421\u0430\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         p1_0.author_id,         a1_0.username      from         posts p1_0      join         users a1_0              on a1_0.id=p1_0.author_id      where         lower(p1_0.title) like lower(('%'||?||'%')) escape ''<\/code><\/pre>\n<h4>Class-based flat projections<\/h4>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u043c \u0434\u043b\u044f Hibernate. \u041d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u044f\u043c\u043e \u0432 JPQL. \u0410\u043b\u0438\u0430\u0441\u044b \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f. \u041f\u0440\u043e\u043a\u0441\u0438 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e DTO-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f.<\/p>\n<pre><code class=\"java\">@Query(\"\"\"             select                 new io.spring.jpa.projection.PostWithAuthorFlatDto(                     a.id,                      a.slug,                      a.title,                      a.author.id,                      a.author.username                 )              from Post a             where lower(a.title) like lower(concat('%', ?1, '%'))\"\"\") List&lt;PostWithAuthorFlatDto&gt; findAllPostWithAuthorFlatDto(String title);<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0435\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"java\">public record PostWithAuthorFlatDto(Long id,                                       String slug,                                       String title,                                       Long authorId,                                       String authorUsername) {   }<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442:<\/p>\n<pre><code class=\"java\">@Test   void queryMethodClassFlat() {       var posts = postRepository.findAllPostWithAuthorFlatDto(\"spring\");       assertEquals(1, posts.size());       PostWithAuthorFlatDto post = posts.getFirst();       assertEquals(POST1_SLUG, post.slug());       assertEquals(POST1_AUTHOR_NAME, post.authorUsername());   }<\/code><\/pre>\n<p>\u0423\u0441\u043f\u0435\u0445:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         p1_0.author_id,         a1_0.username      from         posts p1_0      join         users a1_0              on a1_0.id=p1_0.author_id      where         lower(p1_0.title) like lower(('%'||?||'%')) escape ''<\/code><\/pre>\n<h4>Class-based nested class projections<\/h4>\n<p>\u0412\u0430\u0436\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c HQL, \u0442\u043e <a href=\"https:\/\/docs.jboss.org\/hibernate\/orm\/6.6\/userguide\/html_single\/Hibernate_User_Guide.html#hql-select-new\">\u043c\u043e\u0436\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 DTO<\/a> \u043a\u0430\u043a \u043d\u0430\u043c \u0443\u0434\u043e\u0431\u043d\u043e. \u0412 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u043d\u043e\u0432\u044b\u0435 DTO \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 DTO.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"java\">@Query(\"\"\"             select                 new io.spring.jpa.projection.PostWithAuthorNestedDto(                     a.id,                     a.slug,                     a.title,                     new io.spring.jpa.projection.UserPresentationDto(                         a.author.id,                         a.author.username                     )                 )             from Post a             where lower(a.title) like lower(concat('%', ?1, '%'))\"\"\") List&lt;PostWithAuthorNestedDto&gt; findAllPostWithAuthorNestedDto(String title);<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u043f\u0430\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439 \u043f\u043e\u0434 \u043d\u0435\u0433\u043e: \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430, \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0430.<\/p>\n<pre><code class=\"java\">public record PostWithAuthorNestedDto(Long id,                                         String slug,                                         String title,                                         UserPresentationDto author) {   }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"java\">public record UserPresentationDto(Long id, String username) {   }<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0435\u0441\u0442:<\/p>\n<pre><code class=\"java\">@Test   void queryMethodClassNested() {       var posts = postRepository.findAllPostWithAuthorNestedDto(\"spring\");       assertEquals(1, posts.size());       PostWithAuthorNestedDto post = posts.getFirst();       assertEquals(POST1_SLUG, post.slug());       assertEquals(POST1_AUTHOR_NAME, post.author().username());   }<\/code><\/pre>\n<p>\u041d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         p1_0.author_id,         a1_0.username      from         posts p1_0      join         users a1_0              on a1_0.id=p1_0.author_id      where         lower(p1_0.title) like lower(('%'||?||'%')) escape ''<\/code><\/pre>\n<h4>Tuple, Object[], List&lt;&gt;, Map<\/h4>\n<p>Hibernate \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c select expression, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 <code>Object[]<\/code>, <code>Tuple<\/code>, <code>Map<\/code>, <code>List<\/code>. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u043c, \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043b\u0438\u0448\u044c \u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"java\">@Query(\"\"\"             select                 a.id as id,                 a.slug as slug,                 a.title as title             from Post a             where lower(a.title) like lower(concat('%', ?1, '%'))\"\"\") List&lt;Tuple&gt; findAllTupleBasic(String title);<\/code><\/pre>\n<pre><code class=\"java\">@Query(\"\"\"             select                 a.id as id,                 a.slug as slug,                 a.title as title             from Post a             where lower(a.title) like lower(concat('%', ?1, '%'))\"\"\") List&lt;Object[]&gt; findAllObjectWithAuthor(String title);<\/code><\/pre>\n<pre><code class=\"java\">@Query(\"\"\"             select                 a.id as id,                 a.slug as slug,                 a.title as title             from Post a             where lower(a.title) like lower(concat('%', ?1, '%'))\"\"\") List&lt;List&lt;?&gt;&gt; findAllListWithAuthor(String title);<\/code><\/pre>\n<pre><code class=\"java\">@Query(\"\"\"             select                 a.id as id,                 a.slug as slug,                 a.title as title             from Post a             where lower(a.title) like lower(concat('%', ?1, '%'))\"\"\") List&lt;Map&lt;String, Object&gt;&gt; findAllMapWithAuthor(String title);<\/code><\/pre>\n<p>P.S.: \u0434\u043b\u044f <code>Derived<\/code>-\u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. Spring Data \u0432\u0441\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f <span class=\"habrahidden\">\u0438 \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u0442 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f.<\/span><\/p>\n<h3>Entity Manager<\/h3>\n<p>\u0412\u0441\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f <code>@Query<\/code>, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0438 \u0432 <strong>Entity Manager<\/strong>, \u043a\u0440\u043e\u043c\u0435 <strong>Interface-based projection<\/strong>, \u0442\u0430\u043a \u043a\u0430\u043a  Interface-based projection \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0435\u0439 \u0441\u0430\u043c\u043e\u0433\u043e Spring, \u0441\u0430\u043c \u0436\u0435 Hibernate \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0440\u043e \u043d\u0435\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442.<\/p>\n<h3>Criteria API<\/h3>\n<p><strong>Criteria API<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u0438 \u0433\u0438\u0431\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Java. \u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 Criteria API \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f &#171;type-safe alternative to HQL&#187;. <\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>CriteriaBuilder<\/code>, \u043e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u0438\u0437 <a href=\"https:\/\/docs.jboss.org\/hibernate\/orm\/6.4\/introduction\/html_single\/Hibernate_Introduction.html#criteria-queries\">HibernateCriteriaBuilder<\/a>, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b \u0438 \u0434\u043b\u044f \u043d\u0435\u0433\u043e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441. \u0418\u043c\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b\u043b\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"json\">dependencies { annotationProcessor 'org.hibernate:hibernate-jpamodelgen:{version}' }<\/code><\/pre>\n<pre><code class=\"java\">var idPath = owner.&lt;Long&gt;get(Post_.ID);   var slugPath = owner.&lt;String&gt;get(Post_.SLUG);   var titlePath = owner.&lt;String&gt;get(Post_.TITLE);   var authorIdPath = owner.get(Post_.AUTHOR).&lt;Long&gt;get(User_.ID);   var authorUsernamePath = owner.get(Post_.AUTHOR).&lt;String&gt;get(User_.USERNAME);<\/code><\/pre>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Hibernate \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u0438\u0437 \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u044d\u0442\u043e &#171;\u0442\u0438\u0445\u0430\u044f&#187; \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f.<\/p>\n<p>\u041f\u043e \u0438\u0442\u043e\u0433\u0443 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u043c \u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h4>DTO<\/h4>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 path&#8217;\u044b, \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u0437\u0430\u043a\u0438\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0436\u0438\u0437\u043d\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430:<\/p>\n<pre><code class=\"java\">@Test void criteriaDto() {   var cb = em.getCriteriaBuilder();   var query = cb.createQuery(PostWithAuthorFlatDto.class);      var owner = query.from(Post.class);    var idPath = owner.&lt;Long&gt;get(Post_.ID);   var slugPath = owner.&lt;String&gt;get(Post_.SLUG);   var titlePath = owner.&lt;String&gt;get(Post_.TITLE);   var authorIdPath = owner.get(Post_.AUTHOR).&lt;Long&gt;get(User_.ID);   var authorUsernamePath = owner.get(Post_.AUTHOR).&lt;String&gt;get(User_.USERNAME);    query.multiselect(idPath, slugPath, titlePath, authorIdPath, authorUsernamePath)            .where(cb.like(cb.lower(titlePath), \"%spring%\"));    var resultList = em.createQuery(query).getResultList();    for (PostWithAuthorFlatDto post : resultList) {       assertEquals(POST1_SLUG, post.slug());       assertEquals(POST1_AUTHOR_NAME, post.authorUsername());   } }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0435\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"java\">public record PostWithAuthorFlatDto(Long id,                                       String slug,                                       String title,                                       Long authorId,                                       String authorUsername) {   }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432) \u0438 \u043c\u0430\u043f\u0438\u043c \u0438\u0445 \u043d\u0430 DTO, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 query<\/p>\n<pre><code class=\"java\">jakarta.persistence.criteria.CriteriaBuilder#createQuery(java.lang.Class)<\/code><\/pre>\n<p>\u0423\u0441\u043f\u0435\u0448\u043d\u044b\u0439 \u0443\u0441\u043f\u0435\u0445:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         p1_0.author_id,         a1_0.username      from         posts p1_0      join         users a1_0              on a1_0.id=p1_0.author_id      where         lower(p1_0.title) like ? escape ''<\/code><\/pre>\n<p>\u041a \u043c\u0438\u043d\u0443\u0441\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0447\u0435\u0440\u0435\u0437 DTO \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e, \u0447\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0440\u0438\u0441\u043a \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u0438\u0440\u0438\u043d\u0433\u0430 DTO. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u0439\u043c\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u0447\u0442\u043e \u043d\u0435 \u043d\u0430\u0448\u043b\u043e\u0441\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>Tuple<\/code>.<\/p>\n<h4>Tuple<\/h4>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 <code>Tuple<\/code> \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0440\u0443\u0447\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0438 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u043e\u0439\u043c\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0435\u0449\u0451 \u0434\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<\/p>\n<pre><code class=\"java\">@Test void criteriaTuple() {   var cb = em.getCriteriaBuilder();   var query = cb.createTupleQuery();    var owner = query.from(Post.class);    var idPath = owner.&lt;Long&gt;get(Post_.ID);   var slugPath = owner.&lt;String&gt;get(Post_.SLUG);   var titlePath = owner.&lt;String&gt;get(Post_.TITLE);   var authorIdPath = owner.get(Post_.AUTHOR).&lt;Long&gt;get(User_.ID);   var authorUsernamePath = owner.get(Post_.AUTHOR).&lt;String&gt;get(User_.USERNAME);    query.select(cb.tuple(idPath, slugPath, titlePath, authorIdPath, authorUsernamePath))          .where(cb.like(cb.lower(titlePath), \"%spring%\"));    var resultList = em.createQuery(query).getResultList().stream()            .map(tuple -&gt; new PostWithAuthorNestedDto(                   tuple.get(idPath),                   tuple.get(slugPath),                   tuple.get(titlePath),                   new UserPresentationDto(                            tuple.get(authorIdPath),                            tuple.get(authorUsernamePath)                   )             )).toList();    for (PostWithAuthorNestedDto post : resultList) {       assertEquals(POST1_SLUG, post.slug());       assertEquals(POST1_AUTHOR_NAME, post.author().username());   } }<\/code><\/pre>\n<p>\u0421\u0430\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">public record PostWithAuthorNestedDto(Long id,                                         String slug,                                         String title,                                         UserPresentationDto author) {   }<\/code><\/pre>\n<pre><code class=\"java\">public record UserPresentationDto(Long id, String username) {   }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Path \u043c\u044b \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>Tuple<\/code> \u0438 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0430\u0448\u0435 DTO (\u0435\u0441\u043b\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0432\u044b\u0431\u043e\u0440\u043a\u043e\u0439). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e &#171;type-safe alternative to HQL&#187;, \u043d\u043e \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0443\u044e \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 <code>Tuple<\/code> \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"http:\/\/querydsl.com\/static\/querydsl\/3.4.2\/reference\/html\/ch03s02.html\">QueryDSL<\/a>.<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0439 \u043d\u0430\u0448\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f Criteria API \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0432\u043e\u0442 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/blob\/main\/src\/test\/java\/io\/amplicode\/jpa\/repository\/BasicAttributesTest.java\">\u0442\u0443\u0442<\/a>. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0441\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0442\u0438\u043f\u0438\u0447\u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435.<\/p>\n<h4>CriteriaDefinition \u0432 Hibernate 6.3+<\/h4>\n<p><strong>UPD<\/strong>: \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 6.3, Hibernate \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>CriteriaDefinition<\/code> \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u043d\u043e\u0441\u0442\u0438 criteria-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 <strong>DTO<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">@Test void criteriaDefinitionDto() {     var query = new CriteriaDefinition&lt;&gt;(em, PostWithAuthorFlatDto.class) {{     var owner = from(Post.class);      var titlePath = owner.&lt;String&gt;get(Post_.TITLE);     var authorPath = owner.get(Post_.AUTHOR);      multiselect(               owner.get(Post_.ID),               owner.get(Post_.SLUG),               titlePath,               authorPath.get(User_.ID),               authorPath.get(User_.USERNAME)       ).where(like(lower(titlePath), \"%spring%\"));   }};      var resultList = em.createQuery(query).getResultList();      assertEquals(1, resultList.size());     for (var post : resultList) {         assertEquals(POST1_SLUG, post.slug());         assertEquals(POST1_AUTHOR_NAME, post.authorUsername());     } }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 <strong>Tuple<\/strong>:<\/p>\n<pre><code class=\"java\">@Test void criteriaDefinitionTuple() {     var query = new CriteriaDefinition&lt;&gt;(em, Tuple.class) {};     var owner = query.from(Post.class);      var idPath = owner.&lt;Long&gt;get(Post_.ID);     var slugPath = owner.&lt;String&gt;get(Post_.SLUG);     var titlePath = owner.&lt;String&gt;get(Post_.TITLE);     var authorPath = owner.get(Post_.AUTHOR);     var authorIdPath = authorPath.&lt;Long&gt;get(User_.ID);     var authorUsernamePath = authorPath.&lt;String&gt;get(User_.USERNAME);      query.where(query.like(query.lower(titlePath), \"%spring%\"))             .multiselect(idPath, slugPath, titlePath, authorIdPath, authorUsernamePath);      var resultList = em.createQuery(query).getResultList().stream()             .map(tuple -&gt; new PostWithAuthorNestedDto(                     tuple.get(idPath),                     tuple.get(slugPath),                     tuple.get(titlePath),                     new UserPresentationDto(                             tuple.get(authorIdPath),                             tuple.get(authorUsernamePath)                     )             )).toList();      assertEquals(1, resultList.size());        for (var post : resultList) {         assertEquals(POST1_SLUG, post.slug());         assertEquals(POST1_AUTHOR_NAME, post.author().username());     } }<\/code><\/pre>\n<p>\u041e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0441\u0435\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0434\u043e 6 \u0432\u0435\u0440\u0441\u0438\u0438 Hibernate <code>Criteria API<\/code>-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c <a href=\"https:\/\/vladmihalcea.com\/hibernate-sqm-semantic-query-model\/\">\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/974\/399\/b0b\/974399b0bef5b0e727c746c5b5553bf0.png\" width=\"1149\" height=\"676\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/974\/399\/b0b\/974399b0bef5b0e727c746c5b5553bf0.png\"\/><\/figure>\n<p>Criteria API \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u043e\u0431\u044b\u0447\u043d\u044b\u0439 JPQL, Hibernate \u0436\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b \u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u043e\u0439 HQL, \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0442\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Hibernate 6 Criteria API \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 SQM:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d3d\/07c\/12e\/d3d07c12e54d389bac24f0ea34a22107.png\" width=\"1570\" height=\"676\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d3d\/07c\/12e\/d3d07c12e54d389bac24f0ea34a22107.png\"\/><\/figure>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e SQM \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/vladmihalcea.com\/hibernate-sqm-semantic-query-model\/\">\u0442\u0443\u0442<\/a>.<\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434\u044b<\/h4>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0438\u0448\u0435\u043c HQL\/JPQL query, \u0442\u043e \u043c\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c. \u0412\u043e\u043f\u0440\u043e\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u0430\u043f\u0438\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0438\u0448\u0435\u043c HQL\/JPQL \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c <code>Tuple<\/code> \u0438\u043b\u0438 <code>Map<\/code> \u0438 \u043f\u043e\u043c\u0430\u043f\u0438\u0442\u044c \u0441 \u043d\u0435\u0433\u043e \u043d\u0430 DTO.<\/p>\n<\/li>\n<li>\n<p>&#171;\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 repository derived method?&#187; &#8212;  \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0435\u0448\u0430\u0435\u0442 \u0441\u0430\u043c. \u0412 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438 HQL \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u043c, \u0432 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 &#8212; \u0434\u043b\u0438\u043d\u0430 \u0438\u043c\u0435\u043d\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u0432\u044b\u0439\u0442\u0438 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043d\u0430\u0448\u0435\u0439 \u0441\u043e\u043b\u043d\u0435\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0440\u0435\u0448\u0430\u0435\u043c\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0434\u043b\u044f \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, repository derived method \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u0430\u043c\u044b\u043c \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c. \u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u0430 HQL \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0438\u0437-\u0437\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f DTO\/Projection \u0438\u043b\u0438 \u0441\u0430\u043c\u043e\u0439 Entity.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 <code>Tuple<\/code> , \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 hibernate-jpamodelgen, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0430\u0432\u0442\u043e\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Hibernate \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e &#171;\u0442\u0438\u0445\u0430\u044f&#187; \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f. \u0422\u0430\u043a\u0436\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u0438 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b, \u043b\u0435\u0433\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c jakarta.persistence.criteria.Path \u0434\u043b\u044f Criteria API.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c Query \u0432 Spring Data \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c DTO, \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u0431\u0443\u0434\u0443\u0442 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 DTO: \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u044b \u043a\u0430\u043a \u0442\u0438\u043f\u044b, \u0442\u0430\u043a \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0410 \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 &#8212; \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u043a\u0441\u0438-\u043c\u0430\u0433\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c? \u0412\u0435\u0440\u043d\u0438\u0442\u0435 <code>Tuple<\/code>. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>HQL + Class-Based Projection, \u043e\u043d \u0436\u0435 DTO, \u043e\u043d \u0436\u0435 select new class \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432\u0441\u0435\u0433\u0434\u0430, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f ToMany, \u043f\u0440\u0438 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 Projection\/DTO\/Tuple \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u043c\u0435\u0440\u0434\u0436\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/10b\/00c\/c52\/10b00cc52cc607140b6b496ed3d06436.png\" width=\"1560\" height=\"333\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/10b\/00c\/c52\/10b00cc52cc607140b6b496ed3d06436.png\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043a\u00a0\u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0430\u00a0Spring Boot \u0432\u00a0\u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u00a0\u2014\u00a0<a href=\"https:\/\/t.me\/+oBwACbkvJ19iODAy\">Spring \u0410\u0439\u041e<\/a>, \u0447\u0442\u043e\u0431\u044b\u00a0\u0431\u044b\u0442\u044c \u0432\u00a0\u043a\u0443\u0440\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u043d\u043e\u0432\u043e\u0441\u0442\u0435\u0439 \u0438\u0437\u00a0\u043c\u0438\u0440\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430\u00a0Spring Boot \u0438 \u0432\u0441\u0435\u0433\u043e, \u0447\u0442\u043e\u00a0\u0441\u00a0\u043d\u0438\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043e.<\/p>\n<p>\u0416\u0434\u0435\u043c \u0432\u0441\u0435\u0445,\u00a0<a href=\"https:\/\/t.me\/+oBwACbkvJ19iODAy\">\u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c<\/a>!\u00a0<\/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\/833918\/\"> https:\/\/habr.com\/ru\/articles\/833918\/<\/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>JPA \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0435 \u0437\u0430 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435\u043c. Spring Data JPA \u0438 Hibernate \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u0435\u0431\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.\u00a0<\/p>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 <a href=\"https:\/\/t.me\/+QmrKn0wA8CdkNjAy\">Spring \u0410\u0439\u041e<\/a> \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0430 \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0432 Spring Data JPA \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0430 \u0438\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 corner-\u043a\u0435\u0439\u0441\u044b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 Hibernate \u0432 Spring \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445:<\/p>\n<ul>\n<li>\n<p>Spring Data JPA<\/p>\n<\/li>\n<li>\n<p>EntityManager<\/p>\n<\/li>\n<li>\n<p>Criteria API<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 <a href=\"https:\/\/github.com\/jakartaee\/data\">Jakarta Data<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b\u0448\u043b\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f 1.0.0. \u0420\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u043a\u043e\u043f\u0438\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0439.  <\/p>\n<figure class=\"full-width\"><\/figure>\n<h3>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043b\u0438 \u044d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0445\u043e\u043b\u0438\u0432\u0430\u0440\u0430 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 Telegram-\u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u043f\u0440\u043e Java \u043d\u0430 \u0442\u0435\u043c\u0443 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043b\u043e\u0445 JPA \u0438 Hibernate \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u043a \u043e\u043d \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0433\u0440\u0443\u0437\u0438\u0442\u0441\u044f \u043b\u0438\u0448\u043d\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0442\u0430\u0442\u044c \u043d\u0430 \u0437\u0430\u0449\u0438\u0442\u0443 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u0441\u0442\u044d\u043a\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u0432 \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435 \u043d\u0430 Stackoverflow. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0442\u0435\u0433\u0443 <code>[spring-data-jpa]<\/code> \u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438. \u041c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 <a href=\"https:\/\/stackoverflow.com\/questions\/22007341\/spring-jpa-selecting-specific-columns\">Spring JPA selecting specific columns<\/a>  \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0448\u0435\u0441\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<br \/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0435\u043c\u0441\u044f \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0448\u0438\u0440\u043e\u043a\u043e: \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u043a\u0443\u043d\u0435\u043c\u0441\u044f \u0438 \u0432 \u043c\u0438\u0440 JPA-\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439.<\/p>\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430<\/h3>\n<p>\u0412 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\">\u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/a> \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u043e\u043b\u0435\u0439 + ToOne (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442 author, \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c Post) \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u043f\u0440\u0438\u0447\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u043d\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443, \u0442.\u0435. contains with ignore case. \u0418\u0442\u043e\u0433\u043e \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c <code>Post: id, slug, title; User(author): id, username<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/tree\/main\/src\/test\/java\/io\/amplicode\/jpa\/repository\">\u0442\u0435\u0441\u0442\u0430\u0445<\/a>, \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u0438\u0434\u043d\u044b \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438: \u043b\u043e\u0433, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u0441\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u043b\u0430\u043c\u0438 Hibernate.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 <code>Post<\/code>, \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0432 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u044f \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0432 \u0430\u0432\u0442\u043e\u0440\u043e\u0432. \u0421\u0435\u0440\u0432\u0438\u0441 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/blob\/main\/src\/test\/java\/io\/amplicode\/jpa\/InitTestDataService.java\">InitTestDataService<\/a>.<\/p>\n<h3>toOne<\/h3>\n<p>\u0412\u0441\u0435\u0433\u043e \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d 21 \u0441\u043f\u043e\u0441\u043e\u0431 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u042d\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u0435\u0431\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<ul>\n<li>\n<p>Spring Data Repository derived-methods<\/p>\n<\/li>\n<li>\n<p>Spring Data Repository query-methods<\/p>\n<\/li>\n<li>\n<p>Entity Manager<\/p>\n<\/li>\n<li>\n<p>Criteria API<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 &#8212; <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/blob\/main\/src\/test\/java\/io\/amplicode\/jpa\/repository\/ToOneTest.java\">ToOneTest<\/a>.<\/p>\n<h3>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0432\u043d\u0435\u0441\u0442\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u044f\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0448\u0438\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u043c. <code>Derived<\/code> \u043c\u0435\u0442\u043e\u0434\u044b \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0445 \u0438\u043c\u0435\u043d, \u0442.\u0435. \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/docs.spring.io\/spring-data\/commons\/reference\/repositories\/query-methods.html\">@Query<\/a>. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u044f\u0432\u043d\u043e, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0443 \u043d\u0430\u0441 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c,\u00a0\u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 &#8212; \u044d\u0442\u043e <strong>projection<\/strong>.<\/p>\n<p>\u0421\u0430\u043c\u0438 \u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u0431\u044b\u0432\u0430\u044e\u0442 \u0434\u0432\u0443\u0445 \u0432\u0438\u0434\u043e\u0432: <strong>\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u0445 <\/strong>(Interface-based Projections) \u0438 <strong>\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 <\/strong>(Class-based Projections). <strong>Interface-based Projections <\/strong>\u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0435.<\/p>\n<p>\u0412 <a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/reference\/repositories\/projections.html#projections.interfaces.closed\">\u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0445<\/a> \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f\u0445 \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044f\u0432\u043d\u043e:<\/p>\n<pre><code class=\"java\">interface NamesOnly {   String getFirstname();   String getLastname(); }<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 <a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/reference\/repositories\/projections.html#projections.interfaces.open\">\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439<\/a> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 SpEL \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"java\">interface NamesOnly {       @Value(\"#{target.firstname + ' ' + target.lastname}\")     String getFullName(); }  <\/code><\/pre>\n<p>\u0418\u0445 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u0442.\u043a. \u0432 <a href=\"https:\/\/docs.spring.io\/spring-data\/cassandra\/reference\/repositories\/projections.html#:~:text=Spring%20Data%20cannot%20apply%20query%20execution%20optimizations%20in%20this%20case%2C%20because%20the%20SpEL%20expression%20could%20use%20any%20attribute%20of%20the%20aggregate%20root.\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044f\u0432\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e<\/a>, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0438\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<blockquote>\n<p>Spring Data cannot apply query execution optimizations in this case, because the SpEL expression could use any  attribute of the aggregate root.<\/p>\n<\/blockquote>\n<p>\u0414\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 <strong>ToOne<\/strong>-\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0441 <strong>flatten<\/strong> (\u043f\u043b\u043e\u0441\u043a\u0438\u043c\u0438) \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u0441 <strong>nested<\/strong> (\u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c) \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 <strong>Tuple<\/strong> \u0438 <strong>Map<\/strong>. <\/p>\n<p>\u0414\u043b\u044f <strong>ToMany<\/strong>  \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043f\u043b\u043e\u0441\u043a\u0438\u043c\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e n*m. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0448 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438 \u0434\u043b\u044f ToOne, \u0438 \u0434\u043b\u044f ToMany, \u043e\u0434\u043d\u0430\u043a\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 ToMany<strong> <\/strong>\u0432\u044b\u0433\u0440\u0443\u0437\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u043b\u044f ToOne, \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0438 \u0434\u043b\u044f ToMany, \u043e\u0434\u043d\u0430\u043a\u043e Hibernate \u043d\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043c\u0430\u043f\u0438\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0430 DTO\/Projection, \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0447\u0435\u043c Hibernate \u0432 \u0441\u0438\u043b\u0430\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e HQL, \u0438 \u0434\u043b\u044f \u043a\u0435\u0439\u0441\u0430 \u0441 ToMany \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 n*m. \u0418\u043d\u0430\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043a\u0440\u043e\u043c\u0435 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u043c\u0430\u043f\u0438\u043d\u0433\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0441\u0445\u043b\u043e\u043f\u044b\u0432\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u0415\u0441\u043b\u0438 \u044d\u0442\u0430 \u0442\u0435\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430, \u043c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u043f\u0440\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u0441 ToMany-\u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u044f\u043c\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\">\u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/a> \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 <a href=\"https:\/\/github.com\/comru\/jpa-partial-load\/blob\/main\/src\/test\/java\/io\/amplicode\/jpa\/repository\/ToManyTest.java\">ToManyTest<\/a>. <\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u0434\u0430\u043b\u0435\u0435, \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0438 \u0434\u043b\u044f <strong>Embbeded<\/strong>-\u043a\u0435\u0439\u0441\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430<\/p>\n<h3>Derived-methods<\/h3>\n<h4>Interface-based flat projection<\/h4>\n<p>\u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u0431\u0443\u0434\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u043a \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439.<\/p>\n<p>\u041e\u0431\u044a\u044f\u0432\u0438\u043c \u0432 \u043d\u0430\u0448\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"java\">public interface PostRepository extends JpaRepository&lt;Post, Long&gt; {   &lt;T&gt; List&lt;T&gt; findAllByTitleContainsIgnoreCase(String title, Class&lt;T&gt; projection); }<\/code><\/pre>\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u0446\u0435\u043b\u044f\u0445 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 <a href=\"https:\/\/www.baeldung.com\/spring-data-jpa-projections#dynamic-projections\">\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e<\/a>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<br \/>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\"> public interface PostWithAuthorFlat {       Long getId();       String getSlug();       String getTitle();       Long getAuthorId();       String getAuthorUsername();   }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u0442\u0435\u0441\u0442. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0434\u0435\u0431\u0430\u0433\u043e\u043c. \u0421\u0442\u0430\u0432\u0438\u043c breakpoint \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u0435:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0417\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u043c \u0437\u0432\u0435\u043d\u043e\u043c \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 TupleBackedMap, \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 Tuple \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u043d\u0430\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 breakpoint \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 TupleBackedMap <code>(org.springframework.data.jpa.repository.query.AbstractJpaQuery.TupleConverter.TupleBackedMap)<\/code>:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p> \u0418 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043a\u0441\u0438 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <code>invoke<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 <code>MapAccessingMethodInterceptor<\/code>:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Accessor<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0430\u043c\u043e\u043c\u0443 <code>propertyName<\/code>. \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u0430 \u0432 <code>TupleBackedMap<\/code>. \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0438\u0437 \u0432\u0441\u0435\u043c\u0438 \u043d\u0430\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>Tuple<\/code>:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0421\u0430\u043c \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 <code>Tuple<\/code> \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043b\u044e\u0447\u0443 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<\/p>\n<p>\u0412\u0441\u044e \u0441\u0445\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a:<br \/>\u041f\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0435\u0439 \u043b\u0435\u0436\u0438\u0442 \u043f\u0440\u043e\u043a\u0441\u0438, \u0432 \u043f\u0440\u043e\u043a\u0441\u0438 &#8212; \u043f\u0440\u043e\u043a\u0441\u0438, \u0432 \u043f\u0440\u043e\u043a\u0441\u0438 \u043b\u0435\u0436\u0438\u0442 \u043d\u0435\u043a\u0438\u0439 target-\u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c <code>TupleBackedMap<\/code>.<\/p>\n<p>\u0418\u043b\u0438 \u0442\u0430\u043a:<br \/> <em>\u00ab\u041d\u0430 \u043c\u043e\u0440\u0435 \u043d\u0430 \u043e\u043a\u0435\u0430\u043d\u0435 \u0435\u0441\u0442\u044c \u043e\u0441\u0442\u0440\u043e\u0432, \u043d\u0430 \u0442\u043e\u043c \u043e\u0441\u0442\u0440\u043e\u0432\u0435 \u0434\u0443\u0431 \u0441\u0442\u043e\u0438\u0442, \u043f\u043e\u0434 \u0434\u0443\u0431\u043e\u043c \u0441\u0443\u043d\u0434\u0443\u043a \u0437\u0430\u0440\u044b\u0442, \u0432 \u0441\u0443\u043d\u0434\u0443\u043a\u0435 \u2014 \u0437\u0430\u044f\u0446, \u0432 \u0437\u0430\u0439\u0446\u0435 \u2014 \u0443\u0442\u043a\u0430, \u0432 \u0443\u0442\u043a\u0435 \u2014 \u044f\u0439\u0446\u043e\u00bb<\/em>\u00a0\u0432 \u044f\u0439\u0446\u0435 \u0438\u0433\u043b\u0430 \u2014 \u0441\u043c\u0435\u0440\u0442\u044c \u041a\u043e\u0449\u0435\u044f!<\/p>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e Spring \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u043c\u0430\u043f\u043f\u0438\u0442 <code>Tuple<\/code> \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e. \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0438, \u0432\u0435\u0434\u044c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         p1_0.author_id,         a1_0.username      from         posts p1_0      left join         users a1_0              on a1_0.id=p1_0.author_id      where         upper(p1_0.title) like upper(?) escape '\\'<\/code><\/pre>\n<h4>Interface-based nested interface projections<\/h4>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u043e\u0433\u043b\u043e \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438, \u0438\u043c\u0435\u044e\u0449\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e, \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431 \u0430\u0432\u0442\u043e\u0440\u0435 \u043f\u043e\u0441\u0442\u0430. \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 <strong>nested<\/strong> \u043a\u0435\u0439\u0441.<\/p>\n<pre><code class=\"java\">public interface PostWithAuthorNested {       Long getId();       String getSlug();       String getTitle();       UserPresentation getAuthor();   }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c <code>id<\/code>, <code>slug<\/code>, <code>title<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u044b \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u0447\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u043d\u0430\u0448\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0438 \u0434\u0430\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 <a href=\"https:\/\/github.com\/spring-projects\/spring-data-jpa\/issues\/3352\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442<\/a>. <\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>PostWithAuthorNested<\/code> \u044d\u0442\u043e \u0432\u0441\u0435 \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u043e\u043a\u0441\u0438 \u0432\u043e\u043a\u0440\u0443\u0433 <code>TupleBackedMap<\/code>, \u0430 \u0432\u043e\u0442 \u0441\u0430\u043c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>UserPresentation<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043a\u0441\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u043e\u043a\u0440\u0443\u0433 \u0441\u0430\u043c\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>User<\/code>:<\/p>\n<pre><code class=\"sql\">Hibernate:      select         p1_0.id,         p1_0.slug,         p1_0.title,         a1_0.id,         a1_0.bio,         a1_0.email,         a1_0.image,         a1_0.password,         a1_0.token,         a1_0.username      from         posts p1_0      left join         users a1_0              on a1_0.id=p1_0.author_id      where         upper(p1_0.title) like upper(?) escape '\\'<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433\u0438: \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u043d\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0435 \u0440\u0435\u0448\u0430\u0435\u0442.<\/p>\n<h4>Class-based flat projections<\/h4>\n<p>\u0418\u0434\u0435\u043c \u0434\u0430\u043b\u0435\u0435 \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0435 \u043f\u043e\u043b\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e <code>Record<\/code>-\u043a\u043b\u0430\u0441\u0441\u0430 (\u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c)<\/p>\n<pre><code class=\"java\">public record PostWithAuthorFlatDto(Long id,                                       String slug,                                       String title,                                       Long authorId,                                       String authorUsername) {   }<\/code><\/pre>\n<p>\u0421\u0430\u043c \u0442\u0435\u0441\u0442:<\/p>\n<pre><code class=\"java\">@Test   void derivedMethodClassFlatPrj() {       var posts = postRepository.findAllByTitleContainsIgnoreCase(       \"spring\",       PostWithAuthorFlatDto.class     );       assertEquals(1, posts.size());       var postFirst = posts.getFirst();       assertEquals(POST1_SLUG, postFirst.slug());       assertEquals(POST1_AUTHOR_NAME, postFirst.authorUsername());   }<\/code><\/pre>\n<p><strong>Spring Data JPA<\/strong> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 result type \u0432 Hibernate, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043c\u0430\u043f\u0438\u043d\u0433. \u041d\u0430 \u043f\u043b\u0435\u0447\u0430\u0445 Spring&#8217;\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <strong>JPQL<\/strong> \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-429713","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/429713","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=429713"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/429713\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=429713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=429713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=429713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}