{"id":343003,"date":"2022-12-22T15:00:34","date_gmt":"2022-12-22T15:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343003"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343003","title":{"rendered":"<span>\u041b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e \u043d\u0430 Spring 6<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Spring 6 \u0438 \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0442\u0434\u0430\u0447\u0443 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0421\u043e\u0432\u0435\u0442\u044b \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0439 \u043c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 Spring 6 \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/hypersistence-optimizer\/\" rel=\"noopener noreferrer nofollow\">Hypersistence Optimizer<\/a>\u00a0\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0435\u00a0<a href=\"https:\/\/github.com\/vladmihalcea\/high-performance-java-persistence\" rel=\"noopener noreferrer nofollow\">High-Performance Java Persistence<\/a>.<\/p>\n<h2>Java 17<\/h2>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, Spring 6 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e Java \u0434\u043e 17, \u0438 \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u0438 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<h3>\u0422\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0431\u043b\u043e\u043a\u0438<\/h3>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c \u0431\u043b\u043e\u043a\u0430\u043c \u0432\u0430\u0448\u0438\u00a0\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@Query<\/code> \u0441\u0442\u0430\u043d\u0443\u0442 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"java\">@Query(\"\"\"     select p     from Post p     left join fetch p.comments     where p.id between :minId and :maxId     \"\"\") List&lt;Post> findAllWithComments(     @Param(\"minId\") long minId,     @Param(\"maxId\") long maxId );<\/code><\/pre>\n<blockquote>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0431\u043b\u043e\u043a\u0430\u0445 Java \u0442\u0430\u043a\u0436\u0435 \u0441\u043c. \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/multiline-string-java-text-blocks\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<h3>Records<\/h3>\n<p>Java Records \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f DTO-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439.\u00a0\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u00a0<code>PostRecord<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public record PostCommentRecord(     Long id,     String title,     String review ) {}<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b\u00a0<code>PostCommentRecord<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 Spring Data JPA:<\/p>\n<pre><code class=\"java\">@Query(\"\"\"     select new PostCommentRecord(         p.id as id,         p.title as title,         c.review as review     )     from PostComment c     join c.post p     where p.title like :postTitle     order by c.id     \"\"\") List&lt;PostCommentRecord> findCommentRecordByTitle(     @Param(\"postTitle\") String postTitle );<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u043c\u044f Java-\u043a\u043b\u0430\u0441\u0441\u0430 <code>PostCommentRecord<\/code> \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 JPQL, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <code>ClassImportIntegrator<\/code> \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00a0<a href=\"https:\/\/github.com\/vladmihalcea\/hibernate-types\" rel=\"noopener noreferrer nofollow\">Hibernate Types<\/a>:<\/p>\n<pre><code class=\"java\">properties.put(     \"hibernate.integrator_provider\",     (IntegratorProvider) () -> Collections.singletonList(         new ClassImportIntegrator(             List.of(                 PostCommentRecord.class             )         )     ) );<\/code><\/pre>\n<blockquote>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e Java Records \u0441\u043c. \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/java-records-guide\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<p>\u0418 \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435!\u00a0\u0412 Java 17 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435\u00a0<code>NullPointerException<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0434\u043b\u044f\u00a0<code>switch<\/code> \u0438\u00a0<code>instanceOf<\/code>.<\/p>\n<h2>JPA 3.1<\/h2>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Spring 6 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Hibernate 6.1, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Jakarta Persistence 3.1.<\/p>\n<p>\u0412\u0435\u0440\u0441\u0438\u044f 3.0 \u0437\u043d\u0430\u043c\u0435\u043d\u0443\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e \u0441 Java Persistence \u043d\u0430 Jakarta Persistence, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u043f\u0430\u043a\u0435\u0442\u0430\u00a0<code>javax.persistence<\/code> \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d <code>jakarta.persistence<\/code>.<\/p>\n<p>\u042d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 JPA 3. \u0422\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0431\u044b\u043b\u0430 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044f 3.1, \u043d\u043e \u043e\u043d\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043b\u0438\u0448\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b\u0438\u0441\u044c Hibernate.<\/p>\n<h3>\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 UUID<\/h3>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, JPA 3 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b\u00a0<code>UUID<\/code>:<\/p>\n<pre><code class=\"java\">@Column(     name = \"external_id\",     columnDefinition = \"UUID NOT NULL\" ) private UUID externalId;<\/code><\/pre>\n<p>\u0418 \u0432\u044b \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"java\">@Id @GeneratedValue(strategy = GenerationType.UUID) private UUID id;<\/code><\/pre>\n<p>\u041d\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0436\u0430\u0441\u043d\u0430\u044f \u0438\u0434\u0435\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u00a0<code>UUID<\/code> \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0421\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0435\u0434\u043a\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u043c\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u043e\u0432\u044b\u0439 UUID \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 B+Tree.<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0438\u0437-\u0437\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430<\/p>\n<\/li>\n<li>\n<p>UUID \u043e\u0433\u0440\u043e\u043c\u0435\u043d, \u0435\u043c\u0443 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0430\u0439\u0442\u043e\u0432, \u0447\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0443\u00a0<code>bigint<\/code>.\u00a0\u042d\u0442\u043e \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447, \u043d\u043e \u0438 \u043d\u0430 \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 SQL Server, MySQL \u0438\u043b\u0438 MariaDB, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043a\u0430\u043a\u00a0<a href=\"https:\/\/vladmihalcea.com\/clustered-index\/\" rel=\"noopener noreferrer nofollow\">Clustered Index<\/a>, \u0447\u0442\u043e \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0441\u0443\u0433\u0443\u0431\u0438\u0442 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\u00a0<code>UUID<\/code> \u0434\u043b\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.\u00a0\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u0430\u043c \u043b\u0443\u0447\u0448\u0435\u00a0\u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<a href=\"https:\/\/github.com\/f4b6a3\/tsid-creator\" rel=\"noopener noreferrer nofollow\">64-\u0431\u0438\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 TSID \u0441 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/a>.<\/p>\n<blockquote>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u0442\u043e\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 UUID \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0438\u0445 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c TSID \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439, \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432 <a href=\"https:\/\/vladmihalcea.com\/uuid-database-primary-key\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<h3>\u041d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 JPQL<\/h3>\n<p>\u0412 JPQL \u0431\u044b\u043b\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>CEILING<\/code>, <code>FLOOR<\/code>, <code>EXP<\/code>, <code>LN<\/code>, <code>POWER<\/code>, <code>ROUND<\/code>, <code>SIGN<\/code>.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0438\u0437 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Date\/Time \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>EXTRACT<\/code>:<\/p>\n<pre><code class=\"java\">List&lt;Post> posts = entityManager.createQuery(\"\"\"     select p     from Post p     where EXTRACT(YEAR FROM createdOn) = :year     \"\"\", Post.class) .setParameter(\"year\", Year.now().getValue()) .getResultList();<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u0442\u044b\/\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0443\u044e \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u0441\u043e\u043c\u043d\u0435\u043d\u043d\u043e, \u0443\u0434\u043e\u0431\u043d\u0430.<\/p>\n<h3>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0435\u0441\u044f EntityManager \u0438 EntityManagerFactory<\/h3>\n<p>\u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Hibernate\u00a0<code>Session<\/code>\u0438\u00a0<code>SessionFactory<\/code> \u0443\u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>AutoClosable<\/code>, \u0442\u0435\u043f\u0435\u0440\u044c JPA\u00a0<code>EntityManager<\/code> \u0438\u00a0<code>EntityManagerFactory\u044f<\/code> \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435:<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f86\/c04\/6ad\/f86c046ad68a38a0f66c783d659dc177.png\" width=\"601\" height=\"217\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f86\/c04\/6ad\/f86c046ad68a38a0f66c783d659dc177.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0425\u043e\u0442\u044f \u0432\u0430\u043c \u0440\u0435\u0434\u043a\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Spring \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u0441\u044f \u043e\u0431 <code>EntityManager<\/code> \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0438\u043c\u0435\u043d\u0438, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u00a0<code>EntityManager<\/code>.<\/p>\n<h2>Hibernate 6<\/h2>\n<p>\u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Java 17 \u0438 JPA 3.1 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0432\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439, Hibernate 6 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0443 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439.<\/p>\n<h3>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f JDBC<\/h3>\n<p>\u0420\u0430\u043d\u044c\u0448\u0435 Hibernate \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 JDBC\u00a0<code>ResultSet<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430, \u0438 \u044d\u0442\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u043c.\u00a0\u041f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 Hibernate 6 \u043f\u0435\u0440\u0435\u0448\u0435\u043b \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u043f\u043e \u0438\u0445 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 SQL.<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f, \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u043e\u0442 \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.\u00a0\u0411\u0430\u0437\u043e\u0432\u044b\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 JPQL \u0432 Hibernate 5:<\/p>\n<pre><code class=\"java\">Post post = entityManager.createQuery(\"\"\"     select p     from Post p     join fetch p.comments     where p.id = :id     \"\"\", Post.class) .setParameter(\"id\", 1L) .getSingleResult();<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">SELECT     bidirectio0_.id AS id1_0_0_,     comments1_.id AS id1_1_1_,     bidirectio0_.title AS title2_0_0_,     comments1_.post_id AS post_id3_1_1_,     comments1_.review AS review2_1_1_,     comments1_.post_id AS post_id3_1_0__,     comments1_.id AS id1_1_0__ FROM post     bidirectio0_ INNER JOIN     post_comment comments1_ ON bidirectio0_.id=comments1_.post_id WHERE     bidirectio0_.id=1<\/code><\/pre>\n<p>\u0423\u0440\u043e\u0434\u043b\u0438\u0432\u043e!<\/p>\n<p>\u041a\u0430\u043a, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0442\u043e\u0442 \u0436\u0435 JPQL \u0432 Hibernate 6, \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">SELECT     p1_0.id,     c1_0.post_id,     c1_0.id,     c1_0.review,     p1_0.title FROM     post p1_0 JOIN     post_comment c1_0 ON p1_0.id=c1_0.post_id WHERE     p1_0.id = 1<\/code><\/pre>\n<p>\u0413\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435, \u0432\u0435\u0440\u043d\u043e?<\/p>\n<h3>\u0421\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b Criteria API<\/h3>\n<p>Hibernate 6 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u0430\u043a \u0438\u0437 JPQL, \u0442\u0430\u043a \u0438 \u0438\u0437 Criteria API.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8a2\/db8\/918\/8a2db8918c7bf0a5ef8e48a714e276ad.png\" width=\"623\" height=\"285\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8a2\/db8\/918\/8a2db8918c7bf0a5ef8e48a714e276ad.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0443\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b Criteria API \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f Jakarta Persistence, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0438\u043b\u0438 \u043e\u0431\u0449\u0438\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<blockquote>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 Hibernate (Semantic Query Model) \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/hibernate-sqm-semantic-query-model\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<p>\u0423\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0439 Hibernate Criteria \u0431\u044b\u043b \u0443\u0434\u0430\u043b\u0435\u043d, \u043d\u043e API Criteria \u0431\u044b\u043b \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0447\u0435\u0440\u0435\u0437\u00a0<code>HibernateCriteriaBuilder<\/code>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0<code>ilike<\/code> \u0434\u043b\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f LIKE \u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430:<\/p>\n<pre><code class=\"java\">HibernateCriteriaBuilder builder = entityManager     .unwrap(Session.class)     .getCriteriaBuilder();   CriteriaQuery&lt;Post> criteria = builder.createQuery(Post.class); Root&lt;Post> post = criteria.from(Post.class);   ParameterExpression&lt;String> parameterExpression = builder     .parameter(String.class);       List&lt;Post> posts = entityManager.createQuery(     criteria         .where(             builder.ilike(                 post.get(Post_.TITLE),                 parameterExpression)             )         .orderBy(             builder.asc(                 post.get(Post_.ID)             )         ) ) .setParameter(parameterExpression, titlePattern) .setMaxResults(maxCount) .getResultList();<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440.\u00a0\u0421 \u043d\u043e\u0432\u044b\u043c\u00a0<code>HibernateCriteriaBuilder<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>UNION ALL<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/vladmihalcea.com\/hibernate-jpql-window-functions\/\" rel=\"noopener noreferrer nofollow\">\u041e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/vladmihalcea.com\/sql-derived-table-inline-view\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/vladmihalcea.com\/sql-cte-common-table-expression\/\" rel=\"noopener noreferrer nofollow\">CTE<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/vladmihalcea.com\/sql-recursive-with-cte\/\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 CTE<\/a><\/p>\n<\/li>\n<\/ul>\n<h3>\u0423\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f Dialect<\/h3>\n<p>\u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 Hibernate 5 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0435\u0440\u0441\u0438\u0439\u00a0<code>Dialect<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 Hibernate 6 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/746\/964\/ade\/746964adee8fd78bfded3472423160ec.png\" width=\"3002\" height=\"1369\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/746\/964\/ade\/746964adee8fd78bfded3472423160ec.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432\u0430\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c <code>Dialect<\/code> \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Spring, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0438\u0437 JDBC\u00a0<code>DatabaseMetaData<\/code>.<\/p>\n<blockquote>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441\u00a0<a href=\"https:\/\/vladmihalcea.com\/hibernate-dialect\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439<\/a>.<\/p>\n<\/blockquote>\n<h3>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0412\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u043a\u0430\u043a \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u00a0<code>DISTINCT<\/code> \u0434\u043b\u044f \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u00a0<code>JOIN FETCH<\/code>?<\/p>\n<pre><code class=\"java\">List&lt;Post> posts = entityManager.createQuery(\"\"\"     select distinct p     from Post p     left join fetch p.comments     where p.title = :title     \"\"\", Post.class) .setParameter(\"title\", \"High-Performance Java Persistence\") .setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, false) .getResultList();<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0431\u044b\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443\u00a0<code>PASS_DISTINCT_THROUGH<\/code>, \u0442\u043e Hibernate 5 \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>DISTINCT<\/code> \u0432 SQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"powershell\">Unique    (cost=23.71..23.72 rows=1 width=1068)   (actual time=0.131..0.132 rows=2 loops=1)   ->  Sort          (cost=23.71..23.71 rows=1 width=1068)         (actual time=0.131..0.131 rows=2 loops=1)         Sort Key: p.id, pc.id, p.created_on, pc.post_id, pc.review         Sort Method: quicksort  Memory: 25kB         ->  Hash Right Join              (cost=11.76..23.70 rows=1 width=1068)             (actual time=0.054..0.058 rows=2 loops=1)               Hash Cond: (pc.post_id = p.id)               ->  Seq Scan on post_comment pc                    (cost=0.00..11.40 rows=140 width=532)                   (actual time=0.010..0.010 rows=2 loops=1)               ->  Hash                     (cost=11.75..11.75 rows=1 width=528)                    (actual time=0.027..0.027 rows=1 loops=1)                     Buckets: 1024  Batches: 1  Memory Usage: 9kB                     ->  Seq Scan on post p                          (cost=0.00..11.75 rows=1 width=528)                         (actual time=0.017..0.018 rows=1 loops=1)                           Filter: (                             (title)::text =                             'High-Performance Java Persistence eBook has been released!'::text                           )                           Rows Removed by Filter: 3<\/code><\/pre>\n<blockquote>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u00a0<code>DISTINCT<\/code> \u0432 JPA \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/jpql-distinct-jpa-hibernate\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<p>\u042d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0442\u0430\u043a, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0432\u0430\u0448\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445\u00a0<code>JOIN FETCH<\/code> \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>DISTINCT<\/code>:<\/p>\n<pre><code class=\"java\">List&lt;Post> posts = entityManager.createQuery(\"\"\"     select p     from Post p     left join fetch p.comments     where p.title = :title     \"\"\", Post.class) .setParameter(\"title\", \"High-Performance Java Persistence\") .getResultList();<\/code><\/pre>\n<p>\u041f\u043e\u0442\u0440\u044f\u0441\u0430\u044e\u0449\u0435, \u043f\u0440\u0430\u0432\u0434\u0430?<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>Spring 6 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043d\u0435\u0435 \u043f\u0435\u0440\u0435\u0439\u0442\u0438.\u00a0\u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043e\u0442 \u0432\u0441\u0435\u0445 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 Java 17, \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0430 \u043d\u043e\u0432\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0432\u0441\u0435\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 Spring 6.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Hibernate 6 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u0438 \u043d\u043e\u0432\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u0432\u0430\u0448\u0438\u0445 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u043a \u0434\u043e\u0441\u0442\u0443\u043f\u0443 \u043a \u0434\u0430\u043d\u043d\u044b\u043c.<\/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\/post\/702474\/\"> https:\/\/habr.com\/ru\/post\/702474\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Spring 6 \u0438 \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0442\u0434\u0430\u0447\u0443 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0421\u043e\u0432\u0435\u0442\u044b \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0439 \u043c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 Spring 6 \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/hypersistence-optimizer\/\" rel=\"noopener noreferrer nofollow\">Hypersistence Optimizer<\/a>\u00a0\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0435\u00a0<a href=\"https:\/\/github.com\/vladmihalcea\/high-performance-java-persistence\" rel=\"noopener noreferrer nofollow\">High-Performance Java Persistence<\/a>.<\/p>\n<h2>Java 17<\/h2>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, Spring 6 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e Java \u0434\u043e 17, \u0438 \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u0438 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<h3>\u0422\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0431\u043b\u043e\u043a\u0438<\/h3>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c \u0431\u043b\u043e\u043a\u0430\u043c \u0432\u0430\u0448\u0438\u00a0\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@Query<\/code> \u0441\u0442\u0430\u043d\u0443\u0442 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"java\">@Query(\"\"\"     select p     from Post p     left join fetch p.comments     where p.id between :minId and :maxId     \"\"\") List&lt;Post> findAllWithComments(     @Param(\"minId\") long minId,     @Param(\"maxId\") long maxId );<\/code><\/pre>\n<blockquote>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0431\u043b\u043e\u043a\u0430\u0445 Java \u0442\u0430\u043a\u0436\u0435 \u0441\u043c. \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/multiline-string-java-text-blocks\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<h3>Records<\/h3>\n<p>Java Records \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f DTO-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439.\u00a0\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u00a0<code>PostRecord<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public record PostCommentRecord(     Long id,     String title,     String review ) {}<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b\u00a0<code>PostCommentRecord<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 Spring Data JPA:<\/p>\n<pre><code class=\"java\">@Query(\"\"\"     select new PostCommentRecord(         p.id as id,         p.title as title,         c.review as review     )     from PostComment c     join c.post p     where p.title like :postTitle     order by c.id     \"\"\") List&lt;PostCommentRecord> findCommentRecordByTitle(     @Param(\"postTitle\") String postTitle );<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u043c\u044f Java-\u043a\u043b\u0430\u0441\u0441\u0430 <code>PostCommentRecord<\/code> \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 JPQL, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <code>ClassImportIntegrator<\/code> \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00a0<a href=\"https:\/\/github.com\/vladmihalcea\/hibernate-types\" rel=\"noopener noreferrer nofollow\">Hibernate Types<\/a>:<\/p>\n<pre><code class=\"java\">properties.put(     \"hibernate.integrator_provider\",     (IntegratorProvider) () -> Collections.singletonList(         new ClassImportIntegrator(             List.of(                 PostCommentRecord.class             )         )     ) );<\/code><\/pre>\n<blockquote>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e Java Records \u0441\u043c. \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/java-records-guide\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<p>\u0418 \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435!\u00a0\u0412 Java 17 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435\u00a0<code>NullPointerException<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0434\u043b\u044f\u00a0<code>switch<\/code> \u0438\u00a0<code>instanceOf<\/code>.<\/p>\n<h2>JPA 3.1<\/h2>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Spring 6 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Hibernate 6.1, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Jakarta Persistence 3.1.<\/p>\n<p>\u0412\u0435\u0440\u0441\u0438\u044f 3.0 \u0437\u043d\u0430\u043c\u0435\u043d\u0443\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e \u0441 Java Persistence \u043d\u0430 Jakarta Persistence, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u043f\u0430\u043a\u0435\u0442\u0430\u00a0<code>javax.persistence<\/code> \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d <code>jakarta.persistence<\/code>.<\/p>\n<p>\u042d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 JPA 3. \u0422\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0431\u044b\u043b\u0430 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044f 3.1, \u043d\u043e \u043e\u043d\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043b\u0438\u0448\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b\u0438\u0441\u044c Hibernate.<\/p>\n<h3>\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 UUID<\/h3>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, JPA 3 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b\u00a0<code>UUID<\/code>:<\/p>\n<pre><code class=\"java\">@Column(     name = \"external_id\",     columnDefinition = \"UUID NOT NULL\" ) private UUID externalId;<\/code><\/pre>\n<p>\u0418 \u0432\u044b \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"java\">@Id @GeneratedValue(strategy = GenerationType.UUID) private UUID id;<\/code><\/pre>\n<p>\u041d\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0436\u0430\u0441\u043d\u0430\u044f \u0438\u0434\u0435\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u00a0<code>UUID<\/code> \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0421\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0435\u0434\u043a\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u043c\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u043e\u0432\u044b\u0439 UUID \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 B+Tree.<\/p>\n<\/li>\n<li>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0438\u0437-\u0437\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430<\/p>\n<\/li>\n<li>\n<p>UUID \u043e\u0433\u0440\u043e\u043c\u0435\u043d, \u0435\u043c\u0443 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0430\u0439\u0442\u043e\u0432, \u0447\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0443\u00a0<code>bigint<\/code>.\u00a0\u042d\u0442\u043e \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447, \u043d\u043e \u0438 \u043d\u0430 \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 SQL Server, MySQL \u0438\u043b\u0438 MariaDB, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043a\u0430\u043a\u00a0<a href=\"https:\/\/vladmihalcea.com\/clustered-index\/\" rel=\"noopener noreferrer nofollow\">Clustered Index<\/a>, \u0447\u0442\u043e \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0441\u0443\u0433\u0443\u0431\u0438\u0442 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\u00a0<code>UUID<\/code> \u0434\u043b\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.\u00a0\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u0430\u043c \u043b\u0443\u0447\u0448\u0435\u00a0\u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<a href=\"https:\/\/github.com\/f4b6a3\/tsid-creator\" rel=\"noopener noreferrer nofollow\">64-\u0431\u0438\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 TSID \u0441 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/a>.<\/p>\n<blockquote>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u0442\u043e\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 UUID \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0438\u0445 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c TSID \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439, \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432 <a href=\"https:\/\/vladmihalcea.com\/uuid-database-primary-key\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<h3>\u041d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 JPQL<\/h3>\n<p>\u0412 JPQL \u0431\u044b\u043b\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>CEILING<\/code>, <code>FLOOR<\/code>, <code>EXP<\/code>, <code>LN<\/code>, <code>POWER<\/code>, <code>ROUND<\/code>, <code>SIGN<\/code>.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0438\u0437 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Date\/Time \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>EXTRACT<\/code>:<\/p>\n<pre><code class=\"java\">List&lt;Post> posts = entityManager.createQuery(\"\"\"     select p     from Post p     where EXTRACT(YEAR FROM createdOn) = :year     \"\"\", Post.class) .setParameter(\"year\", Year.now().getValue()) .getResultList();<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u0442\u044b\/\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0443\u044e \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u0441\u043e\u043c\u043d\u0435\u043d\u043d\u043e, \u0443\u0434\u043e\u0431\u043d\u0430.<\/p>\n<h3>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0435\u0441\u044f EntityManager \u0438 EntityManagerFactory<\/h3>\n<p>\u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Hibernate\u00a0<code>Session<\/code>\u0438\u00a0<code>SessionFactory<\/code> \u0443\u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>AutoClosable<\/code>, \u0442\u0435\u043f\u0435\u0440\u044c JPA\u00a0<code>EntityManager<\/code> \u0438\u00a0<code>EntityManagerFactory\u044f<\/code> \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435:<\/p>\n<figure class=\"bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0425\u043e\u0442\u044f \u0432\u0430\u043c \u0440\u0435\u0434\u043a\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Spring \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u0441\u044f \u043e\u0431 <code>EntityManager<\/code> \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0438\u043c\u0435\u043d\u0438, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u00a0<code>EntityManager<\/code>.<\/p>\n<h2>Hibernate 6<\/h2>\n<p>\u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Java 17 \u0438 JPA 3.1 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0432\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439, Hibernate 6 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0443 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439.<\/p>\n<h3>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f JDBC<\/h3>\n<p>\u0420\u0430\u043d\u044c\u0448\u0435 Hibernate \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 JDBC\u00a0<code>ResultSet<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430, \u0438 \u044d\u0442\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u043c.\u00a0\u041f\u043e \u044d\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 Hibernate 6 \u043f\u0435\u0440\u0435\u0448\u0435\u043b \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u043f\u043e \u0438\u0445 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 SQL.<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f, \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u043e\u0442 \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.\u00a0\u0411\u0430\u0437\u043e\u0432\u044b\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 JPQL \u0432 Hibernate 5:<\/p>\n<pre><code class=\"java\">Post post = entityManager.createQuery(\"\"\"     select p     from Post p     join fetch p.comments     where p.id = :id     \"\"\", Post.class) .setParameter(\"id\", 1L) .getSingleResult();<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">SELECT     bidirectio0_.id AS id1_0_0_,     comments1_.id AS id1_1_1_,     bidirectio0_.title AS title2_0_0_,     comments1_.post_id AS post_id3_1_1_,     comments1_.review AS review2_1_1_,     comments1_.post_id AS post_id3_1_0__,     comments1_.id AS id1_1_0__ FROM post     bidirectio0_ INNER JOIN     post_comment comments1_ ON bidirectio0_.id=comments1_.post_id WHERE     bidirectio0_.id=1<\/code><\/pre>\n<p>\u0423\u0440\u043e\u0434\u043b\u0438\u0432\u043e!<\/p>\n<p>\u041a\u0430\u043a, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0442\u043e\u0442 \u0436\u0435 JPQL \u0432 Hibernate 6, \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">SELECT     p1_0.id,     c1_0.post_id,     c1_0.id,     c1_0.review,     p1_0.title FROM     post p1_0 JOIN     post_comment c1_0 ON p1_0.id=c1_0.post_id WHERE     p1_0.id = 1<\/code><\/pre>\n<p>\u0413\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435, \u0432\u0435\u0440\u043d\u043e?<\/p>\n<h3>\u0421\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b Criteria API<\/h3>\n<p>Hibernate 6 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u0430\u043a \u0438\u0437 JPQL, \u0442\u0430\u043a \u0438 \u0438\u0437 Criteria API.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0443\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b Criteria API \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f Jakarta Persistence, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0438\u043b\u0438 \u043e\u0431\u0449\u0438\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<blockquote>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 Hibernate (Semantic Query Model) \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u00a0<a href=\"https:\/\/vladmihalcea.com\/hibernate-sqm-semantic-query-model\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<p>\u0423\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0439 Hibernate Criteria \u0431\u044b\u043b \u0443\u0434\u0430\u043b\u0435\u043d, \u043d\u043e API Criteria \u0431\u044b\u043b \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0447\u0435\u0440\u0435\u0437\u00a0<code>HibernateCriteriaBuilder<\/code>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0<code>ilike<\/code> \u0434\u043b\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f LIKE \u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430:<\/p>\n<pre><code class=\"java\">HibernateCriteriaBuilder builder = entityManager     .unwrap(Session.class)     .getCriteriaBuilder();   CriteriaQuery&lt;Post> criteria = builder.createQuery(Post.class); Root&lt;Post> post = criteria.from(Post.class);   ParameterExpression&lt;String> parameterExpression = builder     .parameter(String.class);       List&lt;Post> posts = entityManager.createQuery(     criteria         .where(             builder.ilike(                 post.get(Post_.TITLE),                 parameterExpression)             )         .orderBy(             builder.asc(                 post.get(Post_.ID)             )         ) ) .setParameter(parameterExpression, titlePattern) .setMaxResults(maxCount) .getResultList();<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440.\u00a0\u0421 \u043d\u043e\u0432\u044b\u043c\u00a0<code>HibernateCriteriaBuilder<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>UNION ALL<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/vladmihalcea.com\/hibernate-jpql-window-functions\/\" rel=\"noopener noreferrer nofollow\">\u041e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/vladmihalcea.com\/sql-derived-table-inline-view\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/vladmihalcea.com\/sql-cte-common-table-expression\/\" rel=\"noopener noreferrer nofollow\">CTE<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/vladmihalcea.com\/sql-recursive-with-cte\/\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 CTE<\/a><\/p>\n<\/li>\n<\/ul>\n<h3>\u0423\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f Dialect<\/h3>\n<p>\u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 Hibernate 5 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0435\u0440\u0441\u0438\u0439\u00a0<code>Dialect<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 Hibernate 6 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043e:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432\u0430\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c <code>Dialect<\/code> \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Spring, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0438\u0437 JDBC\u00a0<code>DatabaseMetaData<\/code>.<\/p>\n<blockquote>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441\u00a0<a href=\"https:\/\/vladmihalcea.com\/hibernate-dialect\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439<\/a>.<\/p>\n<\/blockquote>\n<h3>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0412\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u043a\u0430\u043a \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u00a0<code>DISTINCT<\/code> \u0434\u043b\u044f \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u00a0<code>JOIN FETCH<\/code>?<\/p>\n<pre><code class=\"java\">List&lt;Post> posts = entityManager.createQuery(\"\"\"     select distinct p     from Post p     left join fetch p.comments     where p.title = :title     \"\"\", Post.class) .setParameter(\"title\", \"High-Performance Java Persistence\") .setHint(QueryHints.HINT_PASS_DISTINCT_THROUGH, false) .getResultList();<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0431\u044b\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443\u00a0<code>PASS_DISTINCT_THROUGH<\/code>, \u0442\u043e Hibernate 5 \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>DISTINCT<\/code> \u0432 SQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"powershell\">Unique    (cost=23.71..23.72 rows=1 width=1068)   (actual time=0.131..0.132 rows=2 loops=1)   ->  Sort          (cost=23.71..23.71 rows=1 width=1068)         (actual time=0.131..0.131 rows=2 loops=1)         Sort Key: p.id, pc.id, p.created_on, pc.post_id, pc.review         Sort Method: quicksort  Memory: 25kB         ->  Hash Right Join              (cost=11.76..23.70 rows=1 width=1068)             (actual time=0.054..0.058 rows=2 loops=1)               Hash Cond: (pc.post_id = p.id)               ->  Seq Scan on post_comment pc                    (cost=0.00..11.40 rows=140 width=532)                   (actual time=0.010..0.010 rows=2<\/code><\/pre>\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-343003","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343003","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=343003"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343003\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}