{"id":381649,"date":"2024-06-29T03:47:29","date_gmt":"2024-06-29T03:47:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=381649"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T03:47:29","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=381649","title":{"rendered":"<span>Kotlin + Hibernate: \u0432\u0441\u0451 \u0441\u043b\u043e\u0436\u043d\u043e<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9d0\/53e\/81d\/9d053e81d6ef70bb7e87e997f0054121.png\" width=\"1360\" height=\"600\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d0\/53e\/81d\/9d053e81d6ef70bb7e87e997f0054121.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u0442\u043b\u0438\u043d \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u044f\u0437\u044b\u043a. \u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 Java \u043e\u043d \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u0435\u0435, \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435. \u0422\u0430\u043a\u0436\u0435, \u043a\u043e\u0434 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u041a\u043e\u0442\u043b\u0438\u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 Java-\u043a\u043e\u0434\u043e\u043c. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438, \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043c\u0438\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u041a\u043e\u0442\u043b\u0438\u043d \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0432\u0441\u0451 \u0437\u0430 \u0440\u0430\u0437. \u0422\u0430\u043a\u0438\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u0440\u0438\u0447\u0438\u043d, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 JPA \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u041a\u043e\u0442\u043b\u0438\u043d\u0435. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, JPA \u2014 \u044d\u0442\u043e \u0437\u0440\u0435\u043b\u0430\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u0437\u043d\u0430\u043a\u043e\u043c\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u041a\u043e\u0442\u043b\u0438\u043d\u0435 \u0441 \u043d\u0443\u043b\u044f.\u00a0<\/p>\n<p>\u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c JPA \u0431\u0435\u0437 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u041e\u0434\u043d\u0430\u043a\u043e, \u0438\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432 \u041a\u043e\u0442\u043b\u0438\u043d\u0435 \u0442\u0430\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u0435\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u041a\u043e\u0442\u043b\u0438\u043d\u0430 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c. \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u043f\u043e\u0439\u043b\u0435\u0440! \u041a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0435\u043b\u0435\u043d\u043e Hibernate, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043e\u043c\u043d\u0435\u043d\u043d\u044b\u043c \u043b\u0438\u0434\u0435\u0440\u043e\u043c \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 JPA.<\/p>\n<h3>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f JPA-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439:<\/h3>\n<p>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u2014 \u044d\u0442\u043e \u043d\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 DTO. \u0427\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438, \u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u0430\u0434\u043e \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439. \u0412 <a href=\"https:\/\/download.oracle.com\/otn-pub\/jcp\/persistence-2_1-fr-eval-spec\/JavaPersistence.pdf\">\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 JPA<\/a> \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c, \u0438\u0437 \u043d\u0438\u0445 \u043d\u0430\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u044d\u0442\u0438 \u0434\u0432\u0430:<\/p>\n<blockquote>\n<p><em>1. \u041a\u043b\u0430\u0441\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u041a\u043b\u0430\u0441\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c public \u0438\u043b\u0438 protected.<\/em><\/p>\n<p><em>2. \u041a\u043b\u0430\u0441\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c final. \u041d\u0438\u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c final.<\/em><\/p>\n<\/blockquote>\n<p>\u042d\u0442\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438. \u0427\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0445\u043e\u0440\u043e\u0448\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0435\u0449\u0435 \u043f\u0430\u0440\u043e\u0447\u043a\u0443:<\/p>\n<p>3. Lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u044f\u0432\u043d\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u043b\u0438 \u0441 LazyInitializationException.<\/p>\n<p>4. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>equals()<\/code> \u0438 <code>hashCode()<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<h3>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/h3>\n<p>\u041f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0435 (primary) \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0411\u0435\u0437 \u043d\u0435\u0433\u043e Hibernate \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0431\u0440\u043e\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435: <code>org.hibernate.InstantiationException: No default constructor for entity.<\/code><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043c\u043e\u0436\u043d\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 <a href=\"https:\/\/kotlinlang.org\/docs\/no-arg-plugin.html#jpa-support\"><u>kotlin-jpa<\/u><\/a>. \u042d\u0442\u043e\u0442 \u043f\u043b\u0430\u0433\u0438\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 JPA-\u043a\u043b\u0430\u0441\u0441\u043e\u0432: <code>@Entity<\/code>, <code>@MappedSuperclass<\/code> \u0438\u043b\u0438 <code>@Embeddable<\/code>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c kotlin-jpa, \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 <code>kotlin-maven-plugin<\/code> \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0432 <code>compilerPlugins<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;plugin>    &lt;groupId>org.jetbrains.kotlin&lt;\/groupId>    &lt;artifactId>kotlin-maven-plugin&lt;\/artifactId>    &lt;configuration>        &lt;compilerPlugins>            ...            &lt;plugin>jpa&lt;\/plugin>            ...        &lt;\/compilerPlugins>    &lt;\/configuration>    &lt;dependencies>        ...        &lt;dependency>            &lt;groupId>org.jetbrains.kotlin&lt;\/groupId>            &lt;artifactId>kotlin-maven-noarg&lt;\/artifactId>            &lt;version>${kotlin.version}&lt;\/version>        &lt;\/dependency>        ...    &lt;\/dependencies> &lt;\/plugin><\/code><\/pre>\n<p>\u0412 Gradle:<\/p>\n<pre><code>plugins {   id \"org.jetbrains.kotlin.plugin.jpa\" version \"1.5.21\" }<\/code><\/pre>\n<h3>Open \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/h3>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 JPA, \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 JPA, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c final. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 JPA \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Hibernate \u043d\u0435 \u0431\u0440\u043e\u0441\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442 final \u043a\u043b\u0430\u0441\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u0442 final \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Hibernate. \u041d\u0435\u0442 \u043f\u0440\u043e\u043a\u0441\u0438 \u2014 \u043d\u0435\u0442 lazy \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 ToOne \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u043d\u0435 lazy, \u0430 eager, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0434\u043b\u044f EclipseLink \u0441 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c static weaving, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u044b \u0432 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 lazy \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0414\u0436\u0430\u0432\u044b, \u0432 \u041a\u043e\u0442\u043b\u0438\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e final. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u044f\u0432\u043d\u043e \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>open<\/code>:<\/p>\n<pre><code class=\"kotlin\">Table(name = \"project\") @Entity open class Project {      @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     @Column(name = \"id\", nullable = false)     open var id: Long? = null      @Column(name = \"name\", nullable = false)     open var name: String? = null      ... }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 <a href=\"https:\/\/kotlinlang.org\/docs\/all-open-plugin.html\"><u>all-open<\/u><\/a>. \u041e\u043d \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>open<\/code> \u043f\u0440\u044f\u043c\u043e \u0432 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0435. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u043b\u0441\u044f \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e <code>@Entity<\/code>, \u043d\u043e \u0438 <code>@MappedSuperclass<\/code> \u0438 <code>@Embeddable<\/code>. \u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0434\u043b\u044f Maven:<\/p>\n<pre><code class=\"xml\">&lt;plugin>    &lt;groupId>org.jetbrains.kotlin&lt;\/groupId>    &lt;artifactId>kotlin-maven-plugin&lt;\/artifactId>    &lt;configuration>        &lt;compilerPlugins>            ...            &lt;plugin>all-open&lt;\/plugin>        &lt;\/compilerPlugins>        &lt;pluginOptions>            &lt;option>all-open:annotation=javax.persistence.Entity&lt;\/option>            &lt;option>all-open:annotation=javax.persistence.MappedSuperclass&lt;\/option>            &lt;option>all-open:annotation=javax.persistence.Embeddable&lt;\/option>        &lt;\/pluginOptions>    &lt;\/configuration>    &lt;dependencies>        &lt;dependency>            &lt;groupId>org.jetbrains.kotlin&lt;\/groupId>            &lt;artifactId>kotlin-maven-allopen&lt;\/artifactId>            &lt;version>${kotlin.version}&lt;\/version>        &lt;\/dependency>    &lt;\/dependencies> &lt;\/plugin><\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f Gradle:<\/p>\n<pre><code>plugins {   id \"org.jetbrains.kotlin.plugin.allopen\" version \"1.5.21\" }  allOpen {     annotations(\"javax.persistence.Entity\", \"javax.persistence.MappedSuperclass\", \"javax.persistence.Embedabble\") }<\/code><\/pre>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f JPA-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439<\/h3>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (data classes) \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u041a\u043e\u0442\u043b\u0438\u043d\u0430, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f DTO. \u041a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f final \u043f\u043e \u0437\u0430\u0434\u0443\u043c\u043a\u0435 \u0438 \u0434\u043b\u044f \u043d\u0438\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>equals()<\/code>, <code>hashCode()<\/code> \u0438 <code>toString()<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f JPA-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u0418 \u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u0443 final, \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 open \u0432 \u043a\u043e\u0434\u0435 \u043d\u0435\u043b\u044c\u0437\u044f. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 all-open.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <code>Client<\/code>. \u0423 \u043d\u0435\u0435 \u0435\u0441\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 <code>id<\/code>, \u043f\u043e\u043b\u0435 <code>name<\/code> \u0438 \u0434\u0432\u0435 lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 <code>OneToMany<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Table(name = \"client\") @Entity data class Client(    @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    @Column(name = \"id\", nullable = false)    var id: Long? = null,     @Column(name = \"name\", nullable = false)    var name: String? = null,     @OneToMany(mappedBy = \"client\", orphanRemoval = true)    var projects: MutableSet&lt;Project> = mutableSetOf(),     @JoinColumn(name = \"client_id\")    @OneToMany    var contacts: MutableSet&lt;Contact> = mutableSetOf(), )<\/code><\/pre>\n<h4>\u041d\u0435\u043f\u0440\u0435\u0434\u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439<\/h4>\n<p>\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 ToMany \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e lazy, \u0438 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a: \u0438\u0445 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>equals()<\/code>, <code>hashCode()<\/code> \u0438 <code>toString()<\/code> \u0432 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u043a\u0443\u0434\u0430 \u043c\u043e\u0433\u0443\u0442 \u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0438 lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u044b\u0437\u043e\u0432 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c \u043a \u0411\u0414 \u0438\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e <code>LazyInitializationException<\/code>.<\/p>\n<p>\u041a\u0430\u043a \u0441 \u044d\u0442\u0438\u043c \u0431\u044b\u0442\u044c? \u041c\u0435\u0442\u043e\u0434 <code>toString()<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u0432\u0441\u0435 lazy \u043f\u043e\u043b\u044f. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0438\u0445 \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 IDE. \u0412 <a href=\"https:\/\/plugins.jetbrains.com\/plugin\/15075-jpa-buddy\">JPA Buddy<\/a> \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u043b\u044f <code>toString()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0434\u0430\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c lazy \u043f\u043e\u043b\u044f \u0432 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<pre><code class=\"kotlin\">@Override override fun toString(): String {    return this::class.simpleName + \"(id = $id , name = $name )\" }<\/code><\/pre>\n<p>\u0421 <code>equals()<\/code> \u0438 <code>hashCode()<\/code> \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435: \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438, \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0441 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438.<\/p>\n<h4>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 equals() \u0438 hashCode()<\/h4>\n<p>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0438\u0440\u043e\u0434\u0435. \u0414\u0430\u0436\u0435 ID \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u0435\u0439, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043a\u043e\u043d\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c hashCode.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0435\u0441\u0442 \u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e Client:<\/p>\n<pre><code class=\"kotlin\">val awesomeClient = Client(name = \"Awesome client\")  val hashSet = hashSetOf(awesomeClient)  clientRepository.save(awesomeClient)  assertTrue(awesomeClient in hashSet)<\/code><\/pre>\n<p>Assert \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u0443\u043f\u0430\u0434\u0435\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0445\u043e\u0442\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 Set \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0432\u044b\u0448\u0435. \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 ID \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 hashCode. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 HashSet \u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0438\u0449\u0435\u0442 \u0435\u0433\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0431\u0430\u043a\u0435\u0442\u0435. \u041f\u0440\u043e\u0431\u043b\u0435\u043c \u0431\u044b \u043d\u0435 \u0431\u044b\u043b\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b ID \u0431\u044b\u043b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 ID \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0431\u044b UUID, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c), \u043d\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b <code>equals()<\/code> \u0438 <code>hashCode()<\/code> \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u041a\u0430\u043a \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 <a href=\"https:\/\/vladmihalcea.com\/the-best-way-to-implement-equals-hashcode-and-tostring-with-jpa-and-hibernate\/\"><u>Vlad Mihalcea<\/u><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/thorben-janssen.com\/ultimate-guide-to-implementing-equals-and-hashcode-with-hibernate\/\"><u>Thorben Janssen.<\/u><\/a> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Client<\/code> \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \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=\"kotlin\">override fun equals(other: Any?): Boolean {    if (this === other) return true    if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false    other as Client     return id != null &amp;&amp; id == other.id }  override fun hashCode(): Int = 1756406093<\/code><\/pre>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 ID, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u0435\u0439, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0415\u0441\u043b\u0438 \u043e\u043d \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f, \u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u041f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u2014 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 ID, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c:<\/p>\n<pre><code class=\"kotlin\">@Table(name = \"contact\") @Entity data class Contact(    @Id    @Column(name = \"id\", nullable = false)    val id: UUID, ) {    @Column(name = \"email\", nullable = false)    val email: String? = null     \/\/ other properties omitted }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c ID \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 <code>@NaturalId<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Table(name = \"contact\") @Entity data class Contact(    @NaturalId    @Column(name = \"email\", nullable = false, updatable = false)    val email: String ) {    @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    @Column(name = \"id\", nullable = false)    var id: Long? = null       \/\/ other properties omitted }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441\u0432\u043e\u0434\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u0443 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u043d\u0435\u0442, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0435\u043b\u0430\u0435\u0442 \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 toString(). \u041e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u043b\u0443\u0447\u0448\u0435.<\/p>\n<h3>Null \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c<\/h3>\n<p>\u041e\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u041a\u043e\u0442\u043b\u0438\u043d\u0430 \u043f\u0435\u0440\u0435\u0434 \u0414\u0436\u0430\u0432\u043e\u0439 \u2014 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f null \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c (null safety). \u041e\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0430 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0411\u0414 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 NOT NULL. \u042d\u0442\u0438 \u0434\u0432\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f non-null \u0442\u0438\u043f\u044b \u041a\u043e\u0442\u043b\u0438\u043d\u0430 \u0438 \u0443\u043a\u0430\u0437\u0430\u0432 <code>nullable = false<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Table(name = \"contact\") @Entity class Contact(    @NaturalId    @Column(name = \"email\", nullable = false, updatable = false)    val email: String,     @Column(name = \"name\", nullable = false)    var name: String     @ManyToOne(fetch = FetchType.LAZY, optional = false)    @JoinColumn(name = \"client_id\", nullable = false)    var client: Client ) {    \/\/ id and other properties omitted }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445 \u0438\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0445), \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043b\u0438\u0431\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043f\u043e\u043b\u044e \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 lateinit:<\/p>\n<pre><code class=\"kotlin\">@Entity data class Contact(    @NaturalId    @Column(name = \"email\", nullable = false, updatable = false)    val email: String, ) {    @Column(name = \"name\", nullable = false)    var name: String = \"\"     @ManyToOne(fetch = FetchType.LAZY, optional = false)    @JoinColumn(name = \"client_id\", nullable = false)    lateinit var client: Client     \/\/ id and other properties omitted }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 NULL \u0432 \u0411\u0414, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 null \u0432 Kotlin-\u043a\u043e\u0434\u0435.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044f JPA-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u041a\u043e\u0442\u043b\u0438\u043d\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b:<\/p>\n<ul>\n<li>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 JPA \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b <code>open<\/code>. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u0442 lazy \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0434\u043b\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439 \u00ab<em>\u043c\u043d\u043e\u0433\u0438\u0435\/\u043e\u0434\u0438\u043d<\/em> \u043a <em>\u043e\u0434\u043d\u043e\u043c\u0443\u00bb.<\/em> \u0418\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 <a href=\"https:\/\/kotlinlang.org\/docs\/all-open-plugin.html\"><u>all-open<\/u><\/a> \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u0435\u0433\u043e \u043a\u043e \u0432\u0441\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 <code>@Entity<\/code>, <code>@MappedSuperclass<\/code> \u0438 <code>@Embeddable<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u043e \u0432\u0441\u0435\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 JPA, \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 <a href=\"https:\/\/kotlinlang.org\/docs\/no-arg-plugin.html#jpa-support\"><u>kotlin-jpa<\/u><\/a>. \u0418\u043d\u0430\u0447\u0435 \u0432\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u0442\u0435\u0441\u044c \u0441 InstantiationException.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<ul>\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u043f\u043b\u0430\u0433\u0438\u043d all-open, \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u0442.\u043a. \u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>open<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b <code>equals()<\/code>, <code>hashCode()<\/code> \u0438 <code>toString()<\/code> \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u043e \u0441\u0442\u0430\u0442\u0435\u0439 <a href=\"https:\/\/vladmihalcea.com\/the-best-way-to-implement-equals-hashcode-and-tostring-with-jpa-and-hibernate\/\"><u>Vlad Mihalcea<\/u><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/thorben-janssen.com\/ultimate-guide-to-implementing-equals-and-hashcode-with-hibernate\/\"><u>Thorben Janssen.<\/u><\/a><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/plugins.jetbrains.com\/plugin\/15075-jpa-buddy\"><u>JPA Buddy<\/u><\/a> \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u043b\u044f \u0432\u0430\u0441 \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435\u00a0 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <code>equals()<\/code>, <code>hashCode()<\/code> \u0438 <code>toString()<\/code>. \u0411\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/jpa-buddy\/kotlin-entities\"><u>\u043d\u0430\u0448\u0435\u043c GitHub \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438.<\/u><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/572574\/\"> https:\/\/habr.com\/ru\/articles\/572574\/<\/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<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u0442\u043b\u0438\u043d \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u044f\u0437\u044b\u043a. \u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 Java \u043e\u043d \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u0435\u0435, \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435. \u0422\u0430\u043a\u0436\u0435, \u043a\u043e\u0434 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u041a\u043e\u0442\u043b\u0438\u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 Java-\u043a\u043e\u0434\u043e\u043c. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438, \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043c\u0438\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u041a\u043e\u0442\u043b\u0438\u043d \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0432\u0441\u0451 \u0437\u0430 \u0440\u0430\u0437. \u0422\u0430\u043a\u0438\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043f\u0440\u0438\u0447\u0438\u043d, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 JPA \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u041a\u043e\u0442\u043b\u0438\u043d\u0435. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, JPA \u2014 \u044d\u0442\u043e \u0437\u0440\u0435\u043b\u0430\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u0437\u043d\u0430\u043a\u043e\u043c\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u041a\u043e\u0442\u043b\u0438\u043d\u0435 \u0441 \u043d\u0443\u043b\u044f.\u00a0<\/p>\n<p>\u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c JPA \u0431\u0435\u0437 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u041e\u0434\u043d\u0430\u043a\u043e, \u0438\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432 \u041a\u043e\u0442\u043b\u0438\u043d\u0435 \u0442\u0430\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u0435\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u041a\u043e\u0442\u043b\u0438\u043d\u0430 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c. \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u043f\u043e\u0439\u043b\u0435\u0440! \u041a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0435\u043b\u0435\u043d\u043e Hibernate, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043e\u043c\u043d\u0435\u043d\u043d\u044b\u043c \u043b\u0438\u0434\u0435\u0440\u043e\u043c \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 JPA.<\/p>\n<h3>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f JPA-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439:<\/h3>\n<p>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u2014 \u044d\u0442\u043e \u043d\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 DTO. \u0427\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438, \u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u0430\u0434\u043e \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439. \u0412 <a href=\"https:\/\/download.oracle.com\/otn-pub\/jcp\/persistence-2_1-fr-eval-spec\/JavaPersistence.pdf\">\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 JPA<\/a> \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c, \u0438\u0437 \u043d\u0438\u0445 \u043d\u0430\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u044d\u0442\u0438 \u0434\u0432\u0430:<\/p>\n<blockquote>\n<p><em>1. \u041a\u043b\u0430\u0441\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u041a\u043b\u0430\u0441\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c public \u0438\u043b\u0438 protected.<\/em><\/p>\n<p><em>2. \u041a\u043b\u0430\u0441\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c final. \u041d\u0438\u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c final.<\/em><\/p>\n<\/blockquote>\n<p>\u042d\u0442\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438. \u0427\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0445\u043e\u0440\u043e\u0448\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0435\u0449\u0435 \u043f\u0430\u0440\u043e\u0447\u043a\u0443:<\/p>\n<p>3. Lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u044f\u0432\u043d\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u043b\u0438 \u0441 LazyInitializationException.<\/p>\n<p>4. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>equals()<\/code> \u0438 <code>hashCode()<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<h3>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/h3>\n<p>\u041f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0435 (primary) \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0411\u0435\u0437 \u043d\u0435\u0433\u043e Hibernate \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0431\u0440\u043e\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435: <code>org.hibernate.InstantiationException: No default constructor for entity.<\/code><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043c\u043e\u0436\u043d\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 <a href=\"https:\/\/kotlinlang.org\/docs\/no-arg-plugin.html#jpa-support\"><u>kotlin-jpa<\/u><\/a>. \u042d\u0442\u043e\u0442 \u043f\u043b\u0430\u0433\u0438\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 JPA-\u043a\u043b\u0430\u0441\u0441\u043e\u0432: <code>@Entity<\/code>, <code>@MappedSuperclass<\/code> \u0438\u043b\u0438 <code>@Embeddable<\/code>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c kotlin-jpa, \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 <code>kotlin-maven-plugin<\/code> \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0432 <code>compilerPlugins<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;plugin>    &lt;groupId>org.jetbrains.kotlin&lt;\/groupId>    &lt;artifactId>kotlin-maven-plugin&lt;\/artifactId>    &lt;configuration>        &lt;compilerPlugins>            ...            &lt;plugin>jpa&lt;\/plugin>            ...        &lt;\/compilerPlugins>    &lt;\/configuration>    &lt;dependencies>        ...        &lt;dependency>            &lt;groupId>org.jetbrains.kotlin&lt;\/groupId>            &lt;artifactId>kotlin-maven-noarg&lt;\/artifactId>            &lt;version>${kotlin.version}&lt;\/version>        &lt;\/dependency>        ...    &lt;\/dependencies> &lt;\/plugin><\/code><\/pre>\n<p>\u0412 Gradle:<\/p>\n<pre><code>plugins {   id \"org.jetbrains.kotlin.plugin.jpa\" version \"1.5.21\" }<\/code><\/pre>\n<h3>Open \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/h3>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 JPA, \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 JPA, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c final. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 JPA \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Hibernate \u043d\u0435 \u0431\u0440\u043e\u0441\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442 final \u043a\u043b\u0430\u0441\u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u0442 final \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Hibernate. \u041d\u0435\u0442 \u043f\u0440\u043e\u043a\u0441\u0438 \u2014 \u043d\u0435\u0442 lazy \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 ToOne \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u043d\u0435 lazy, \u0430 eager, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0434\u043b\u044f EclipseLink \u0441 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c static weaving, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u044b \u0432 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 lazy \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0414\u0436\u0430\u0432\u044b, \u0432 \u041a\u043e\u0442\u043b\u0438\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e final. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u044f\u0432\u043d\u043e \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>open<\/code>:<\/p>\n<pre><code class=\"kotlin\">Table(name = \"project\") @Entity open class Project {      @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     @Column(name = \"id\", nullable = false)     open var id: Long? = null      @Column(name = \"name\", nullable = false)     open var name: String? = null      ... }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 <a href=\"https:\/\/kotlinlang.org\/docs\/all-open-plugin.html\"><u>all-open<\/u><\/a>. \u041e\u043d \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>open<\/code> \u043f\u0440\u044f\u043c\u043e \u0432 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0435. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u043b\u0441\u044f \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e <code>@Entity<\/code>, \u043d\u043e \u0438 <code>@MappedSuperclass<\/code> \u0438 <code>@Embeddable<\/code>. \u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0434\u043b\u044f Maven:<\/p>\n<pre><code class=\"xml\">&lt;plugin>    &lt;groupId>org.jetbrains.kotlin&lt;\/groupId>    &lt;artifactId>kotlin-maven-plugin&lt;\/artifactId>    &lt;configuration>        &lt;compilerPlugins>            ...            &lt;plugin>all-open&lt;\/plugin>        &lt;\/compilerPlugins>        &lt;pluginOptions>            &lt;option>all-open:annotation=javax.persistence.Entity&lt;\/option>            &lt;option>all-open:annotation=javax.persistence.MappedSuperclass&lt;\/option>            &lt;option>all-open:annotation=javax.persistence.Embeddable&lt;\/option>        &lt;\/pluginOptions>    &lt;\/configuration>    &lt;dependencies>        &lt;dependency>            &lt;groupId>org.jetbrains.kotlin&lt;\/groupId>            &lt;artifactId>kotlin-maven-allopen&lt;\/artifactId>            &lt;version>${kotlin.version}&lt;\/version>        &lt;\/dependency>    &lt;\/dependencies> &lt;\/plugin><\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f Gradle:<\/p>\n<pre><code>plugins {   id \"org.jetbrains.kotlin.plugin.allopen\" version \"1.5.21\" }  allOpen {     annotations(\"javax.persistence.Entity\", \"javax.persistence.MappedSuperclass\", \"javax.persistence.Embedabble\") }<\/code><\/pre>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f JPA-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439<\/h3>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (data classes) \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u041a\u043e\u0442\u043b\u0438\u043d\u0430, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f DTO. \u041a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f final \u043f\u043e \u0437\u0430\u0434\u0443\u043c\u043a\u0435 \u0438 \u0434\u043b\u044f \u043d\u0438\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>equals()<\/code>, <code>hashCode()<\/code> \u0438 <code>toString()<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f JPA-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u0418 \u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u0443 final, \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 open \u0432 \u043a\u043e\u0434\u0435 \u043d\u0435\u043b\u044c\u0437\u044f. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 all-open.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <code>Client<\/code>. \u0423 \u043d\u0435\u0435 \u0435\u0441\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 <code>id<\/code>, \u043f\u043e\u043b\u0435 <code>name<\/code> \u0438 \u0434\u0432\u0435 lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 <code>OneToMany<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Table(name = \"client\") @Entity data class Client(    @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    @Column(name = \"id\", nullable = false)    var id: Long? = null,     @Column(name = \"name\", nullable = false)    var name: String? = null,     @OneToMany(mappedBy = \"client\", orphanRemoval = true)    var projects: MutableSet&lt;Project> = mutableSetOf(),     @JoinColumn(name = \"client_id\")    @OneToMany    var contacts: MutableSet&lt;Contact> = mutableSetOf(), )<\/code><\/pre>\n<h4>\u041d\u0435\u043f\u0440\u0435\u0434\u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439<\/h4>\n<p>\u0410\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 ToMany \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e lazy, \u0438 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a: \u0438\u0445 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>equals()<\/code>, <code>hashCode()<\/code> \u0438 <code>toString()<\/code> \u0432 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u043a\u0443\u0434\u0430 \u043c\u043e\u0433\u0443\u0442 \u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0438 lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u044b\u0437\u043e\u0432 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c \u043a \u0411\u0414 \u0438\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e <code>LazyInitializationException<\/code>.<\/p>\n<p>\u041a\u0430\u043a \u0441 \u044d\u0442\u0438\u043c \u0431\u044b\u0442\u044c? \u041c\u0435\u0442\u043e\u0434 <code>toString()<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u0432\u0441\u0435 lazy \u043f\u043e\u043b\u044f. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0438\u0445 \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 IDE. \u0412 <a href=\"https:\/\/plugins.jetbrains.com\/plugin\/15075-jpa-buddy\">JPA Buddy<\/a> \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u043b\u044f <code>toString()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0434\u0430\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c lazy \u043f\u043e\u043b\u044f \u0432 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<pre><code class=\"kotlin\">@Override override fun toString(): String {    return this::class.simpleName + \"(id = $id , name = $name )\" }<\/code><\/pre>\n<p>\u0421 <code>equals()<\/code> \u0438 <code>hashCode()<\/code> \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435: \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 lazy \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438, \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0441 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438.<\/p>\n<h4>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 equals() \u0438 hashCode()<\/h4>\n<p>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0438\u0440\u043e\u0434\u0435. \u0414\u0430\u0436\u0435 ID \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u0435\u0439, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043a\u043e\u043d\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c hashCode.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0435\u0441\u0442 \u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e Client:<\/p>\n<pre><code class=\"kotlin\">val awesomeClient = Client(name = \"Awesome client\")  val hashSet = hashSetOf(awesomeClient)  clientRepository.save(awesomeClient)  assertTrue(awesomeClient in hashSet)<\/code><\/pre>\n<p>Assert \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u0443\u043f\u0430\u0434\u0435\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0445\u043e\u0442\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 Set \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0432\u044b\u0448\u0435. \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 ID \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 hashCode. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 HashSet \u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0438\u0449\u0435\u0442 \u0435\u0433\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0431\u0430\u043a\u0435\u0442\u0435. \u041f\u0440\u043e\u0431\u043b\u0435\u043c \u0431\u044b \u043d\u0435 \u0431\u044b\u043b\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b ID \u0431\u044b\u043b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 ID \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0431\u044b UUID, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c), \u043d\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b <code>equals()<\/code> \u0438 <code>hashCode()<\/code> \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u041a\u0430\u043a \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 <a href=\"https:\/\/vladmihalcea.com\/the-best-way-to-implement-equals-hashcode-and-tostring-with-jpa-and-hibernate\/\"><u>Vlad Mihalcea<\/u><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/thorben-janssen.com\/ultimate-guide-to-implementing-equals-and-hashcode-with-hibernate\/\"><u>Thorben Janssen.<\/u><\/a> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Client<\/code> \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \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=\"kotlin\">override fun equals(other: Any?): Boolean {    if (this === other) return true    if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false    other as Client     return id != null &amp;&amp; id == other.id }  override fun hashCode(): Int = 1756406093<\/code><\/pre>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 ID, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c<\/h4>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043b\u0435\u0439, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0415\u0441\u043b\u0438 \u043e\u043d \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f, \u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u041f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u2014 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 ID, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c:<\/p>\n<pre><code class=\"kotlin\">@Table(name = \"contact\") @Entity data class Contact(    @Id    @Column(name = \"id\", nullable = false)    val id: UUID, ) {    @Column(name = \"email\", nullable = false)    val email: String? = null     \/\/ other properties omitted }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c ID \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 <code>@NaturalId<\/code>:<\/p>\n<pre><code class=\"kotlin\">@Table(name = \"contact\") @Entity data class Contact(    @NaturalId    @Column(name = \"email\", nullable = false, updatable = false)    val email: String ) {<\/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-381649","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/381649","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=381649"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/381649\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=381649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=381649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=381649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}