{"id":16832,"date":"2011-12-15T10:00:27","date_gmt":"2011-12-15T08:00:27","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=16832"},"modified":"2013-09-04T01:16:02","modified_gmt":"2013-09-03T22:16:02","slug":"persistence-layer-with-spring-data-jpa","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html","title":{"rendered":"The Persistence Layer with Spring Data JPA"},"content":{"rendered":"<h2>1. Overview<\/h2>\n<p>This article will focus on the configuration and implementation of the persistence layer with <strong>Spring 3.1, JPA and Spring Data<\/strong>. For a step by step introduction about setting up the Spring context using Java based configuration and the basic Maven pom for the project, see <a title=\"Bootstrapping a web application with Spring 3.1 and Java based Configuration, part 1\" href=\"http:\/\/www.baeldung.com\/2011\/10\/20\/bootstraping-a-web-application-with-spring-3-1-and-java-based-configuration-part-1\/\" target=\"_blank\">this article<\/a>.<\/p>\n<p>The <strong>Persistence with Spring<\/strong> <a title=\"Spring Persistence Series\" href=\"http:\/\/www.baeldung.com\/persistence-with-spring-series\/\" target=\"_blank\">series<\/a>:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<ul>\n<li><strong>Part 1<\/strong> \u2013 <a title=\"The Persistence Layer with Spring 3.1 and Hibernate\" href=\"http:\/\/www.baeldung.com\/2011\/12\/02\/the-persistence-layer-with-spring-3-1-and-hibernate\/\" target=\"_blank\" rel=\"nofollow\">The Persistence Layer with Spring 3.1 and Hibernate<\/a><\/li>\n<li><strong>Part 2<\/strong> \u2013 <a title=\"Simplifying the Data Access Layer with Spring and Java Generics\" href=\"http:\/\/www.baeldung.com\/2011\/12\/08\/simplifying-the-data-access-layer-with-spring-and-java-generics\/\" target=\"_blank\" rel=\"nofollow\">Simplifying the Data Access Layer with Spring and Java Generics<\/a><\/li>\n<li><strong>Part 3<\/strong> \u2013 <a title=\"The Persistence Layer with Spring 3.1 and JPA\" href=\"http:\/\/www.baeldung.com\/2011\/12\/13\/the-persistence-layer-with-spring-3-1-and-jpa\/\" target=\"_blank\" rel=\"nofollow\">The Persistence Layer with Spring 3.1 and JPA<\/a><\/li>\n<li><strong>Part 4<\/strong> \u2013 <a title=\"The Persistence Layer with Spring Data JPA\" href=\"http:\/\/www.baeldung.com\/2011\/12\/22\/the-persistence-layer-with-spring-data-jpa\/\" target=\"_blank\" rel=\"nofollow\">The Persistence Layer with Spring Data JPA<\/a><\/li>\n<li><strong>Part 5<\/strong> \u2013 <a title=\"Transaction configuration with JPA and Spring 3.1\" href=\"http:\/\/www.baeldung.com\/2011\/12\/26\/transaction-configuration-with-jpa-and-spring-3-1\/\" target=\"_blank\" rel=\"nofollow\">Transaction configuration with JPA and Spring 3.1<\/a><\/li>\n<\/ul>\n<h2>2. No More DAO implementations<\/h2>\n<p>As discussed in an earlier article, <a title=\"Removing the boilerplate from the DAO\" href=\"http:\/\/www.baeldung.com\/2011\/12\/08\/simplifying-the-data-access-layer-with-spring-and-java-generics\/\">the DAO layer<\/a> usually consists of a lot of boilerplate code that can and should be simplified. The advantages of such a simplification are many fold: a decrease in the number of artifacts that need to be defined and maintained, simplification and\u00a0consistency of data access patterns and consistency of configuration.<\/p>\n<p>Spring Data takes this simplification one step forward and makes it possible to <strong>remove the DAO implementations entirely<\/strong> \u2013 the interface of the DAO is now the only artifact that need to be explicitly defined.<\/p>\n<h2>3. The Spring Data managed DAO<\/h2>\n<p>In order to start leveraging the Spring Data programming model with JPA, a DAO interface needs to extend the JPA specific <em>Repository<\/em> interface &#8211;\u00a0<em>JpaRepository<\/em> \u2013 in Spring\u2019s interface hierarchy. This will enable Spring Data to find this interface and automatically create an implementation for it.<\/p>\n<p>Also, by extending the interface we get most if not all relevant CRUD generic methods for standard data access available in the DAO.<\/p>\n<h2>4. Defining custom access method and queries<\/h2>\n<p>As discussed, by implementing one of the <em>Repository<\/em> interfaces, the DAO will already have some basic CRUD methods (and queries) defined and implemented. To define more specific access methods, Spring JPA supports quite a few options \u2013 you can either simply<strong> define a new method<\/strong> in the interface, or you can <strong>provide the actual JPQ query<\/strong> by using the <em>@Query<\/em> annotation.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>A third option to define custom queries is to make use of\u00a0JPA Named Queries, but this has the disadvantage that it either involves XML or burdening the domain class with the queries.<\/p>\n<p>In addition to these, Spring Data <a title=\"Spring Data Specification API\" href=\"http:\/\/blog.springsource.org\/2011\/04\/26\/advanced-spring-data-jpa-specifications-and-querydsl\/\" target=\"_blank\">introduces<\/a> a more flexible and convenient API, similar to the JPA Criteria API, only more readable and reusable. The advantages of this API will become more pronounced when dealing with a large number of fixed queries that could potentially be more concisely expressed through a smaller number of reusable blocks that keep occurring in different combinations.<\/p>\n<h4>4.1. Automatic Custom Queries<\/h4>\n<p>When Spring Data creates a new <em>Repository<\/em> implementation, it analyses all the methods defined by the interfaces and tries to automatically generate queries from <strong>the method name<\/strong>. While this has limitations, it is a very powerful and elegant way of defining new custom access methods with very little effort.<\/p>\n<p>For example, if the managed entity has a <em>name <\/em>field (and the Java Bean standard getter and setter for that field), defining the <strong><em>findByName<\/em> method<\/strong> in the DAO interface will automatically generate the correct query:<\/p>\n<pre class=\" brush:java\">public interface IFooDAO extends JpaRepository&lt; Foo, Long &gt;{\r\n\r\n   Foo findByName( final String name );\r\n\r\n}<\/pre>\n<p>This is a relatively simple example; <a title=\"Spring Data JPA - Query creation\" href=\"http:\/\/static.springsource.org\/spring-data\/data-jpa\/docs\/1.1.x\/reference\/html\/#jpa.query-methods.query-creation\" target=\"_blank\" rel=\"nofollow\">a much larger set of keywords<\/a> is supported by query creation mechanism.<\/p>\n<p>In the case that the parser cannot match the property with the domain object field, the following exception is thrown:<\/p>\n<p>java.lang.IllegalArgumentException: No property <strong>nam<\/strong> found for type class org.rest.model.Foo<\/p>\n<h4>4.2. Manual Custom Queries<\/h4>\n<p>In addition to deriving the query from the method name, a custom query can be manually specified with the method level <em>@Query<\/em> annotation.<\/p>\n<p>For even more fine grained control over the creation of queries, such as using named parameters or modifying existing queries, <a title=\"Spring Data JPA - Query creation additional options\" href=\"http:\/\/static.springsource.org\/spring-data\/data-jpa\/docs\/1.1.x\/reference\/html\/#jpa.named-parameters\" target=\"_blank\" rel=\"nofollow\">the reference<\/a> is a good place to start.<\/p>\n<h2>5. Spring Data transaction configuration<\/h2>\n<p>The actual implementation of the Spring Data managed DAO \u2013 <em>SimpleJpaRepository<\/em> \u2013 uses annotations to <strong>define and configure transactions<\/strong>. A read only <em>@Transactional<\/em> annotation is used at the class level, which is then overridden for the non read-only methods. The rest of the transaction semantics are default, but these can be easily overridden manually per method.<\/p>\n<h4>5.1. Exception Translation without the template<\/h4>\n<p>One of the responsibilities of Spring ORM templates (<em>JpaTemplate<\/em>, <em>HibernateTemplate<\/em>) is <strong>exception translation<\/strong> \u2013 translating JPA exceptions \u2013 which tie the API to JPA \u2013 to Spring\u2019s <em>DataAccessException<\/em> hierarchy.<\/p>\n<p>Without the template to do that, exception translation can still be enabled by annotating the DAOs with the <em>@Repository<\/em> annotation. That, coupled with a Spring bean postprocessor will advice all <em>@Repository<\/em> beans with all the implementations of <em>PersistenceExceptionTranslator<\/em> found in the Container \u2013 to provide exception translation without using the template.<\/p>\n<p>The fact that exception translation is indeed active can easily be verified with an <strong>integration test<\/strong>:<\/p>\n<pre class=\" brush:java\">@Test( expected = DataAccessException.class )\r\npublic void whenAUniqueConstraintIsBroken_thenSpringSpecificExceptionIsThrown(){\r\n   String name = \"randomName\";\r\n   service.save( new Foo( name ) );\r\n   service.save( new Foo( name ) );\r\n}<\/pre>\n<p>Exception translation is done through proxies; in order for Spring to be able to create proxies around the DAO classes, these must not be declared <em><strong>final<\/strong><\/em>.<\/p>\n<h2>6. Spring Data Configuration<\/h2>\n<p>To activate the Spring JPA repository support, the <strong><em>jpa<\/em> namespace<\/strong> is defined and used to specify the package where to DAO interfaces are located:<\/p>\n<pre class=\" brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans\r\n   xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n   xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n   xmlns:jpa=\"http:\/\/www.springframework.org\/schema\/data\/jpa\"\r\n   xsi:schemaLocation=\"\r\n      http:\/\/www.springframework.org\/schema\/beans\r\n      http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd\r\n      http:\/\/www.springframework.org\/schema\/data\/jpa\r\n      http:\/\/www.springframework.org\/schema\/data\/jpa\/spring-jpa.xsd\"&gt;\r\n\r\n&lt;jpa:repositories base-package=\"org.rest.dao.spring\" \/&gt;\r\n\r\n&lt;\/beans&gt;<\/pre>\n<p>At this point, there is no equivalent Java based configuration \u2013 support for it is however <a title=\"Repositories scanning using java-config - JIRA\" href=\"https:\/\/jira.springsource.org\/browse\/DATAJPA-69\" target=\"_blank\" rel=\"nofollow\">in the works<\/a>.<\/p>\n<h2>7. The Spring Java or XML configuration<\/h2>\n<p>The previous article of the series already discussed in great detail how to <a title=\"The Spring 3.1 and JPA Tutorial\" href=\"http:\/\/www.baeldung.com\/2011\/12\/13\/the-persistence-layer-with-spring-3-1-and-jpa\/\">configure JPA in Spring 3<\/a>. Spring Data also takes advantage of the Spring support for the JPA <em>@PersistenceContext<\/em> annotation which it uses to wire the <em>EntityManager<\/em> into the Spring factory bean responsible with creating the actual DAO implementations \u2013 <em>JpaRepositoryFactoryBean<\/em>.<\/p>\n<p>In addition to the already discussed configuration, there is one last missing piece \u2013 including the Spring Data XML configuration in the overall persistence configuration:<\/p>\n<pre class=\" brush:java\">@Configuration\r\n@EnableTransactionManagement\r\n@ImportResource( \"classpath*:*springDataConfig.xml\" )\r\npublic class PersistenceJPAConfig{\r\n   ...\r\n}<\/pre>\n<h2>8. The Maven configuration<\/h2>\n<p>In addition to the Maven configuration for JPA defined in a <a title=\"The Persistence Layer with Spring 3.1 and JPA\" href=\"http:\/\/www.baeldung.com\/2011\/12\/13\/the-persistence-layer-with-spring-3-1-and-jpa\/\" target=\"_blank\">previous article<\/a>, the <em>spring-data-jpa<\/em> dependency is added:<\/p>\n<pre class=\" brush:xml\">&lt;dependency&gt;\r\n   &lt;groupId&gt;org.springframework.data&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;spring-data-jpa&lt;\/artifactId&gt;\r\n   &lt;version&gt;1.3.2.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<h2>9. Conclusion<\/h2>\n<p>This article covered the configuration and implementation of the persistence layer with Spring 3.1, JPA 2 and Spring JPA (part of the Spring Data umbrella project), using both XML and Java based configuration. The various method of defining more <strong>advanced custom queries<\/strong> are discussed, as well as <strong>configuration with the new <em>jpa<\/em> namespace<\/strong> and transactional semantics. The final result is a new and elegant take on data access with Spring, with almost no actual implementation work. You can check out the full implementation in the <a title=\"the github REST project containing the implementation for this post\" href=\"https:\/\/github.com\/eugenp\/REST#readme\" target=\"_blank\" rel=\"nofollow\">github project<\/a>.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/www.baeldung.com\/2011\/12\/22\/the-persistence-layer-with-spring-data-jpa\/\">The Persistence Layer with Spring Data JPA<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Eugen Paraschiv at the <a href=\"http:\/\/www.baeldung.com\/\">baeldung<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Overview This article will focus on the configuration and implementation of the persistence layer with Spring 3.1, JPA and Spring Data. For a step by step introduction about setting up the Spring context using Java based configuration and the basic Maven pom for the project, see this article. The Persistence with Spring series: &nbsp; &hellip;<\/p>\n","protected":false},"author":104,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[33,30,321],"class_list":["post-16832","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jpa","tag-spring","tag-spring-data"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Persistence Layer with Spring Data JPA<\/title>\n<meta name=\"description\" content=\"1. Overview This article will focus on the configuration and implementation of the persistence layer with Spring 3.1, JPA and Spring Data. For a step by\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Persistence Layer with Spring Data JPA\" \/>\n<meta property=\"og:description\" content=\"1. Overview This article will focus on the configuration and implementation of the persistence layer with Spring 3.1, JPA and Spring Data. For a step by\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-12-15T08:00:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-09-03T22:16:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Eugen Paraschiv\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/baeldung\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eugen Paraschiv\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html\"},\"author\":{\"name\":\"Eugen Paraschiv\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7a8ad27f4bb34bb3664fda07d3142bc4\"},\"headline\":\"The Persistence Layer with Spring Data JPA\",\"datePublished\":\"2011-12-15T08:00:27+00:00\",\"dateModified\":\"2013-09-03T22:16:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html\"},\"wordCount\":1061,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"JPA\",\"Spring\",\"Spring Data\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html\",\"name\":\"The Persistence Layer with Spring Data JPA\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2011-12-15T08:00:27+00:00\",\"dateModified\":\"2013-09-03T22:16:02+00:00\",\"description\":\"1. Overview This article will focus on the configuration and implementation of the persistence layer with Spring 3.1, JPA and Spring Data. For a step by\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/persistence-layer-with-spring-data-jpa.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"The Persistence Layer with Spring Data JPA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7a8ad27f4bb34bb3664fda07d3142bc4\",\"name\":\"Eugen Paraschiv\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g\",\"caption\":\"Eugen Paraschiv\"},\"sameAs\":[\"http:\\\/\\\/www.baeldung.com\\\/\",\"http:\\\/\\\/www.linkedin.com\\\/in\\\/eugenparaschiv\",\"https:\\\/\\\/x.com\\\/http:\\\/\\\/twitter.com\\\/baeldung\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Eugen-Paraschiv\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Persistence Layer with Spring Data JPA","description":"1. Overview This article will focus on the configuration and implementation of the persistence layer with Spring 3.1, JPA and Spring Data. For a step by","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html","og_locale":"en_US","og_type":"article","og_title":"The Persistence Layer with Spring Data JPA","og_description":"1. Overview This article will focus on the configuration and implementation of the persistence layer with Spring 3.1, JPA and Spring Data. For a step by","og_url":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-12-15T08:00:27+00:00","article_modified_time":"2013-09-03T22:16:02+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Eugen Paraschiv","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/baeldung","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Eugen Paraschiv","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html"},"author":{"name":"Eugen Paraschiv","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7a8ad27f4bb34bb3664fda07d3142bc4"},"headline":"The Persistence Layer with Spring Data JPA","datePublished":"2011-12-15T08:00:27+00:00","dateModified":"2013-09-03T22:16:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html"},"wordCount":1061,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["JPA","Spring","Spring Data"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html","url":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html","name":"The Persistence Layer with Spring Data JPA","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2011-12-15T08:00:27+00:00","dateModified":"2013-09-03T22:16:02+00:00","description":"1. Overview This article will focus on the configuration and implementation of the persistence layer with Spring 3.1, JPA and Spring Data. For a step by","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/persistence-layer-with-spring-data-jpa.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"The Persistence Layer with Spring Data JPA"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7a8ad27f4bb34bb3664fda07d3142bc4","name":"Eugen Paraschiv","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g","caption":"Eugen Paraschiv"},"sameAs":["http:\/\/www.baeldung.com\/","http:\/\/www.linkedin.com\/in\/eugenparaschiv","https:\/\/x.com\/http:\/\/twitter.com\/baeldung"],"url":"https:\/\/www.javacodegeeks.com\/author\/Eugen-Paraschiv"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/16832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/104"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=16832"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/16832\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=16832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=16832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=16832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}