{"id":289584,"date":"2018-09-19T01:25:03","date_gmt":"2018-09-18T21:25:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=289584"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=289584","title":{"rendered":"\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c Spring Data JDBC"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0412 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0440\u0435\u043b\u0438\u0437 Spring Data \u043f\u043e\u0434 \u043a\u043e\u0434\u043e\u0432\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c <em>Lovelace<\/em> \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c: <a href=\"https:\/\/projects.spring.io\/spring-data-jdbc\/\">Spring Data JDBC<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0434\u0435\u044f Spring Data JDBC \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 <strong>\u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 JPA<\/strong>. <\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>JPA \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u0430\u043a <em>\u043b\u0435\u043d\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<\/em> (lazy loading), <em>\u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/em> \u0438 <em>\u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439<\/em> (dirty tracking). \u041d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u044d\u0442\u0438 \u0444\u0438\u0447\u0438 \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0443\u0442\u044b\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u0430\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u044b, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c. <\/p>\n<p>  <\/p>\n<p>\u041c\u0435\u0445\u043d\u0438\u0437\u043c <em>\u043b\u0435\u043d\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438<\/em> \u043c\u043e\u0436\u0435\u0442 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0435\u043c\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0438\u043b\u0438 \u0438 \u0432\u043e\u0432\u0441\u0435 \u0443\u043f\u0430\u0441\u0442\u044c \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c. <em>\u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/em> \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0442\u0430\u0442\u044c \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0440\u0435\u0448\u0438\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0434\u0432\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 entity, \u0430 \u0432\u043a\u0443\u043f\u0435 \u0441 <em>\u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439<\/em> \u043f\u043e\u043c\u0435\u0448\u0430\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c \u2014 \u0432 \u043a\u0430\u043a\u043e\u0439 \u0436\u0435 \u043c\u043e\u043c\u0435\u043d\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445?<\/p>\n<p>  <\/p>\n<p>Spring Data JDBC \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 <strong>\u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/strong>. \u041d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u0438\u043b\u0438 \u043b\u0435\u043d\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e, SQL \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0442\u043e\u0433\u0434\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0432\u044b\u0437\u0432\u0430\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430. \u041d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 &#171;\u0441\u0435\u0441\u0438\u0438&#187; \u0438\u043b\u0438 \u043f\u0440\u043e\u043a\u0441\u0438-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0434\u043b\u044f entities. \u0418 \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c Spring Data JDBC \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0442\u0430\u043a\u043e\u0439 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u044b\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0446\u0435\u043b\u044b\u0439 \u0440\u044f\u0434 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u0430\u0445. \u0413\u0440\u044f\u0434\u0443\u0449\u0438\u0439 \u0440\u0435\u043b\u0438\u0437 \u044d\u0442\u043e \u0441\u0430\u043c\u0430\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u043b\u0430\u043d\u043e\u0432 \u0438 \u0437\u0430\u043c\u044b\u0441\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u043e \u043c\u044b \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u044b \u0438\u0445 \u043e\u0442\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0442\u044c \u0432\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f Spring Data JDBC \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u043d\u044c\u0448\u0435. <\/p>\n<p>  <\/p>\n<h1 id=\"primer\">\u041f\u0440\u0438\u043c\u0435\u0440<\/h1>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c entity:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">class Customer {     @Id     Long id;     String firstName;     LocalDate dob; }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0438 \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432, \u043d\u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u043e\u0432. \u0412\u044b, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435. \u0412 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u043a entity \u2014 \u044d\u0442\u043e \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u043b\u0435 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <code>Id<\/code> (\u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e <code>org.springframework.data.annotation.Id<\/code>, \u0430 \u043d\u0435 <code>javax.persistence one<\/code>).<\/p><\/blockquote>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435, \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>CrudRepository<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">interface CustomerRepository extends CrudRepository&lt;Customer, Long&gt; {}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>ApplicationContext<\/code> \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Configuration @EnableJdbcRepositories (1) public class CustomerConfig extends JdbcConfiguration { (2)      @Bean     NamedParameterJdbcOperations operations() { (3)         return new NamedParameterJdbcTemplate(dataSource());     }      @Bean     PlatformTransactionManager transactionManager() { (4)         return new DataSourceTransactionManager(dataSource());     }      @Bean     DataSource dataSource(){ (5)         return new EmbeddedDatabaseBuilder()                 .generateUniqueName(true)                 .setType(EmbeddedDatabaseType.HSQL)                 .addScript(\"create-customer-schema.sql\")                 .build();     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<ol>\n<li><code>EnableJdbcRepositories<\/code> \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\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 \u0431\u0438\u043d\u043e\u0432, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<\/li>\n<li>\u0422.\u043a. \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 <code>JdbcConfiguration<\/code>, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u043d\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0418\u0445 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u044c, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 Spring Data JDBC. \u041d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/li>\n<li>\u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u044d\u0442\u043e <code>NamedParameterJdbcOperations<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435.<\/li>\n<li>\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, \u0441\u0442\u0440\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d. \u041d\u043e \u0431\u0435\u0437 \u043d\u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, \u0430 \u044d\u0442\u043e \u043c\u0430\u043b\u043e \u043a\u043e\u043c\u0443 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u043f\u0440\u0430\u0432\u0434\u0430?<\/li>\n<li>Spring Data JDBC \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>DataSource<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043d\u043e <code>TransactionManager<\/code> \u0438 <code>NamedParameterJdbcOperation<\/code> \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0435\u0433\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0431\u0438\u043d.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e Spring Data JDBC. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RunWith(SpringRunner.class) @Transactional @ContextConfiguration(classes = CustomerConfig.class) public class CustomerRepositoryTest {      @Autowired CustomerRepository customerRepo;      @Test     public void createSimpleCustomer() {          Customer customer = new Customer();         customer.dob = LocalDate.of(1904, 5, 14);         customer.firstName = \"Albert\";          Customer saved = customerRepo.save(customer);          assertThat(saved.id).isNotNull();          saved.firstName = \"Hans Albert\";          customerRepo.save(saved);          Optional&lt;Customer&gt; reloaded = customerRepo.findById(saved.id);          assertThat(reloaded).isNotEmpty();          assertThat(reloaded.get().firstName).isEqualTo(\"Hans Albert\");     } }<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"annotaciya-query\">\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@Query<\/code><\/h1>\n<p>  <\/p>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 CRUD \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 <code>CrudRepository<\/code> \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0443\u0435\u0434\u0435\u0448\u044c. \u041c\u044b \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u0440\u0435\u0448\u0438\u043b\u0438 \u043e\u0442\u043b\u043e\u0436\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0443\u044e \u0444\u0438\u0447\u0443 Spring Data, \u043a\u043e\u0433\u0434\u0430 SQL \u0437\u0430\u043f\u0440\u043e\u0441 \u0433\u0435\u043d\u0435\u0440\u0438\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u043c\u0435\u043d\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u2014 \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0438\u0435 \u0440\u0435\u043b\u0438\u0437\u044b. \u0410 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0443\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@Query<\/code> \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u0447\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 SQL \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Query(\"select id, first_name, dob from customer where upper(first_name) like '%' || upper(:name) || '%' \") List&lt;Customer&gt; findByName(@Param(\"name\") String name);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435, \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043c\u0435\u0442\u043e\u0434\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@Modifying<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430\u0448 \u043d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Test public void findByName() {      Customer customer = new Customer();     customer.dob = LocalDate.of(1904, 5, 14);     customer.firstName = \"Albert\";      Customer saved = customerRepo.save(customer);      assertThat(saved.id).isNotNull();      customer.id= null; (1)     customer.firstName = \"Bertram\";      customerRepo.save(customer);      customer.id= null;     customer.firstName = \"Beth\";      customerRepo.save(customer);      assertThat(customerRepo.findByName(\"bert\")).hasSize(2); (2) }<\/code><\/pre>\n<p>  <\/p>\n<ol>\n<li>\u0422.\u043a. \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 Java \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0432 \u0431\u0430\u0437\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043f\u043e\u043b\u044e <code>Id<\/code> \u0438 \u0442\u0438\u043f\u0443, \u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 <code>Id<\/code>\u0432 <code>null<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c.<\/li>\n<li>\u0412 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c case-sensitive like, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u00ab\u00a0Albert\u00a0\u00bb \u0438 \u00ab\u00a0Bertram\u00a0\u00bb, \u043d\u043e \u043d\u0435 \u00ab\u00a0Beth\u00a0\u00bb.<\/li>\n<\/ol>\n<p>  <\/p>\n<h1 id=\"v-zavershenie\">\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e Spring Data JDBC \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0438 \u043c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445. <\/p>\n<p>  <\/p>\n<p>\u0410 \u043f\u043e\u043a\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c <a href=\"https:\/\/github.com\/spring-projects\/spring-data-examples\/tree\/master\/jdbc\">\u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432<\/a>, <a href=\"https:\/\/docs.spring.io\/spring-data\/jdbc\/docs\/1.0.0.RC2\/reference\/html\/\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/a>, \u0438, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, <a href=\"https:\/\/github.com\/spring-projects\/spring-data-jdbc\">\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a>. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u2014 \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u0438\u0445 <a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/spring-data-jdbc\">\u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430 StackOverflow<\/a>. \u0410 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0448\u043b\u0438 \u0431\u0430\u0433 \u0438\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0444\u0438\u0447\u0443 \u2014 \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, <a href=\"https:\/\/jira.spring.io\/projects\/DATAJDBC\">\u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0442\u0438\u043a\u0435\u0442<\/a>.<\/p>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <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\/post\/423697\/\"> https:\/\/habr.com\/post\/423697\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0412 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0440\u0435\u043b\u0438\u0437 Spring Data \u043f\u043e\u0434 \u043a\u043e\u0434\u043e\u0432\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c <em>Lovelace<\/em> \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c: <a href=\"https:\/\/projects.spring.io\/spring-data-jdbc\/\">Spring Data JDBC<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0434\u0435\u044f Spring Data JDBC \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 <strong>\u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 JPA<\/strong>. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-289584","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/289584","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=289584"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/289584\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=289584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=289584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=289584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}