{"id":106338,"date":"2020-08-18T07:00:04","date_gmt":"2020-08-18T04:00:04","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=106338"},"modified":"2020-08-10T15:07:31","modified_gmt":"2020-08-10T12:07:31","slug":"spring-boot-data-jpa-beginner-guide","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html","title":{"rendered":"Spring Boot Data JPA &#8211; beginner guide"},"content":{"rendered":"<p>Databases form an integral part of computer applications. With it comes considerable amount of database operations and the corresponding code. For huge applications which have large number of tables\/entities, these operations or the code is repeated and duplicated to a large extent. Eventually a programmer would like to reduce this duplicate code. Spring framework took up the challenge and provided us with a solution in the form of Spring Data JPA.<\/p>\n<p>Spring Data is one of the most useful feature released by Spring team. JPA stands for Java Persistence API.<\/p>\n<p>Spring Data JPA provides repository abstraction. This means that the common or repetitive code for the repository is generated by Spring data. The programmer need not write that code again and again for all the repositories. <br \/>Thus using Spring Data reduces the boilerplate code from persistence layers.<\/p>\n<h2 class=\"wp-block-heading\">Features of Spring Data can be listed as<\/h2>\n<ul class=\"wp-block-list\">\n<li>The Spring Data generates implementation. That means we do not need to implement DAO manually anymore<\/li>\n<li>Spring Data JPA reduces the boilerplate code required by JPA<\/li>\n<li>That helps to implement persistence layer easier and faster<\/li>\n<li>The DAO implementations to be completely removed<\/li>\n<\/ul>\n<p>Spring Data JPA can be used with a normal Spring application as well as a Spring boot application. We shall look at both ways further in this blog.<\/p>\n<h2 class=\"wp-block-heading\">4 steps to configure Spring Data JPA:<\/h2>\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/stacktraceguru.com\/springboot\/spring-data-jpa#extend-with-repository-interface\">Extend Repository interface<\/a><\/li>\n<li><a href=\"https:\/\/stacktraceguru.com\/springboot\/spring-data-jpa#declare-queries-using-spring-data\">Declare query methods in the interface<\/a><\/li>\n<li><a href=\"https:\/\/stacktraceguru.com\/springboot\/spring-data-jpa#configurations\">Set up Spring for instantiating these interfaces<\/a><\/li>\n<li><a href=\"https:\/\/stacktraceguru.com\/springboot\/spring-data-jpa#access-repository-classes\">Inject these instances for use<\/a><\/li>\n<\/ol>\n<h3 class=\"wp-block-heading\">1) Extend Repository interface<\/h3>\n<p>In order to use Spring data with JPA, our repository or DAO interface must extend JPA specific repository interface.<\/p>\n<p>This will enable Spring data to find our interface and automatically create implementation for it. Thus, our DAO interface can extend Repository interface,&nbsp;JpaRepository&nbsp;interface or any of its sub interface.<\/p>\n<p>Extending sub interface indirectly extends Repository interface.<\/p>\n<p>The Repository interface is the most important interface in Spring Data. It is marker interface. Repository interface takes Domain class and id type as generic type arguments.<\/p>\n<div>\n<div id=\"highlighter_171920\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">Syntax: <\/code><code class=\"c keyword bold\">public<\/code> <code class=\"c plain\">interface Repository&lt;T, ID&gt;<\/code><\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;<\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"c plain\">T- Domain type, ID- id data type<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Example for use of Repository interface<\/p>\n<div>\n<div id=\"highlighter_486542\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">interface StudentRepository extends Repository&lt;Student, Long&gt; { \u2026 }<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>There are some sub interfaces provided by spring data for additional functionalities. Some of the sub interfaces are,<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>public interface&nbsp;CrudRepository&lt;T, ID&gt;:<\/strong> It provides basic CRUD functionalities.<br \/>eg: interface&nbsp;StudentRepository&nbsp;extends&nbsp;CrudRepository&lt;Student, Long&gt; { \u2026 }<\/li>\n<li><strong>public interface&nbsp;PagingAndSortingRepository&lt;T, ID&gt;:<\/strong> this interface provides paging and sorting functionalities in addition to CRUD operations.<br \/>eg: interface&nbsp;StudentRepository&nbsp;extends&nbsp;PagingAndSortingRepository &lt;Student, Long&gt; { \u2026 }<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">2) Declare query methods on the interface<\/h3>\n<p>Once we have created the interface for our entity, it\u2019s time to create methods. As discussed, Spring data JPA has a feature that implements repository methods for us. All we have to do is tell Spring data what methods we need.<\/p>\n<p><strong> 2 ways to define method in spring data JPA<\/strong><\/p>\n<ol class=\"wp-block-list\">\n<li><a href=\"#derive-from-method-name\">By deriving the query from the method name&nbsp;<\/a><\/li>\n<li><a href=\"#using-query-annotation\">Manual query using \u201c@Query\u201d annotation<\/a><\/li>\n<\/ol>\n<h2 class=\"wp-block-heading\">2.1) By deriving the query from the method name<\/h2>\n<p>It is as straight forward as the name suggests. All we need to do is, name the method in such a way that it tells what exactly the method wants.<\/p>\n<p>For instance, If we want to fetch data for the Student with department id.<br \/>The corresponding method name will be like,&nbsp;<\/p>\n<div>\n<div id=\"highlighter_714798\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">List&lt;Student&gt; findByDepartmentId(Long departmentId);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>As we can see that the method is in plain English and easy to understand.<\/p>\n<p>Assume a Student has a Department object. In Department we have id. In that case, the method creates the property traversal&nbsp;student.department.id.<\/p>\n<p>This method will create following query<\/p>\n<div>\n<div id=\"highlighter_218843\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">select * from Student where departmentId = ?1;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>In general our interface will look like below,<\/p>\n<div>\n<div id=\"highlighter_837388\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">interface StudentRepository extends Repository&lt;Student, Long&gt; {<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">List&lt;Student&gt; findByDepartmentId(Long departmentId);<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"c plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>For this purpose, Spring data has reserved some key words such as, the prefixes find_By, read_By, query_By, count_By, and get_By in the method.<\/p>\n<p>We can also use the keywords such as AND&nbsp;and&nbsp;OR to create&nbsp;qurey&nbsp;with multiple properties of an entity. We also get support for operators such as Between,&nbsp;LessThan,&nbsp;GreaterThan, and Like for the property expressions.<\/p>\n<p>These supported operators can vary by database of choice. So consulting the appropriate part of reference documentation is advised. You can read more at <a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/docs\/2.3.0.RELEASE\/reference\/html\/#jpa.query-methods.query-creation\">keywords in spring data.<\/a><\/p>\n<h2 class=\"wp-block-heading\">2.2) Manual query using \u201c@Query\u201d annotation<\/h2>\n<p>Using meaningful method name for repository sounds very interesting, however sometimes that is not enough.&nbsp;Specially&nbsp;if we need multiple properties in queries or complex query.<\/p>\n<p>We can create method but the name of the method can be very long.<\/p>\n<div>\n<div id=\"highlighter_487823\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">List&lt;Student&gt; findByFirstNameAndLastNameOrderByFirstnameAsc(String firstName,String lastName);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>In such cases we can use @query annotation provided by Spring Data.&nbsp;<\/p>\n<div>\n<div id=\"highlighter_219185\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">@Query(<\/code><code class=\"c string\">\"SELECT s FROM Student s WHERE s.firstName =?1 or s.lastName =?2 order by firstName asc)\"<\/code><code class=\"c plain\">)<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"c plain\">List&lt;Student&gt; findByName(String firstName,String lastName);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Using position based parameter (?paramPosition) could be difficult to understand and refactor.&nbsp;This&nbsp;can be avoided by using named-parameters in query. We can use \u201c<em>:paramName<\/em>\u201d and <em>\u201c@Param<\/em>\u201d annotation for parameter binding.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<div>\n<div id=\"highlighter_194747\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">@Query(<\/code><code class=\"c string\">\"SELECT s FROM Student s WHERE s.firstName = :firstName or s.lastName = :lastName order by firstName asc)\"<\/code><code class=\"c plain\">)<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"c plain\">List&lt;Student&gt; findByName(@Param(<\/code><code class=\"c string\">\"firstName\"<\/code><code class=\"c plain\">)String firstName, @Param(<\/code><code class=\"c string\">\"lastName\"<\/code><code class=\"c plain\">)String lastName);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3 class=\"wp-block-heading\">3) Configuration for spring data JPA<\/h3>\n<p>Spring Data&nbsp;JPA&nbsp;can be used in basic spring or spring-boot project. Also the configuration can be&nbsp;done&nbsp;using xml or java classes. For configuration using java class, we need to use @Configuration annotation.<\/p>\n<h2 class=\"wp-block-heading\">3.1 Spring data JPA configuration in spring boot:<\/h2>\n<p>Spring boot is another very famous framework, which make application creation and management very fast and easy. It has auto configuration feature which provides all required dependencies and configuration. We just need to add correct dependencies.<\/p>\n<p>It also auto configures Spring data and hibernate as default JPA. Also it provides all necessary configuration required for spring data according to database used. We just need to add correct database connector dependency and provide&nbsp;data source.<\/p>\n<p>We don\u2019t need to do other configuration unless, we need to customize it.<\/p>\n<h2 class=\"wp-block-heading\">Spring&nbsp;boot configuration using&nbsp;application.properties<\/h2>\n<div>\n<div id=\"highlighter_920009\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">spring.datasource.url=jdbc:mysql:<\/code><code class=\"c comments\">\/\/localhost:3306\/database_name<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"c plain\">spring.datasource.username=root <\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"c plain\">spring.datasource.password=root<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\">3.2 Spring data JPA configuration in non-spring boot:<\/h2>\n<p>To use spring data we need to configure following objects:<\/p>\n<ol class=\"wp-block-list\">\n<li><strong>DataSource<\/strong>:&nbsp;Database configuration- URL, username, password, driver,&nbsp;etc<\/li>\n<li><strong>EntityManager<\/strong>: Most important object which binds all objects, like entity package,&nbsp;datasource,&nbsp;etc\n<ol>\n<li>we can configure entityManager&nbsp;using&nbsp;LocalEntityManagerFactoryBean<\/li>\n<li>we can also configure additional properties using&nbsp;setJpaProperties(properties)<\/li>\n<\/ol>\n<\/li>\n<li><strong>TransactionManager<\/strong>: Configuration for database transaction<\/li>\n<\/ol>\n<h2 class=\"wp-block-heading\">Configuration using java code:<\/h2>\n<div>\n<div id=\"highlighter_947593\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">01<\/div>\n<div class=\"line number2 index1 alt1\">02<\/div>\n<div class=\"line number3 index2 alt2\">03<\/div>\n<div class=\"line number4 index3 alt1\">04<\/div>\n<div class=\"line number5 index4 alt2\">05<\/div>\n<div class=\"line number6 index5 alt1\">06<\/div>\n<div class=\"line number7 index6 alt2\">07<\/div>\n<div class=\"line number8 index7 alt1\">08<\/div>\n<div class=\"line number9 index8 alt2\">09<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<div class=\"line number20 index19 alt1\">20<\/div>\n<div class=\"line number21 index20 alt2\">21<\/div>\n<div class=\"line number22 index21 alt1\">22<\/div>\n<div class=\"line number23 index22 alt2\">23<\/div>\n<div class=\"line number24 index23 alt1\">24<\/div>\n<div class=\"line number25 index24 alt2\">25<\/div>\n<div class=\"line number26 index25 alt1\">26<\/div>\n<div class=\"line number27 index26 alt2\">27<\/div>\n<div class=\"line number28 index27 alt1\">28<\/div>\n<div class=\"line number29 index28 alt2\">29<\/div>\n<div class=\"line number30 index29 alt1\">30<\/div>\n<div class=\"line number31 index30 alt2\">31<\/div>\n<div class=\"line number32 index31 alt1\">32<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">@Configuration<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"c plain\">@EnableJpaRepositories<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"c plain\">@EnableTransactionManagement<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"c keyword bold\">class<\/code> <code class=\"c plain\">ApplicationConfig {<\/code><\/div>\n<div class=\"line number5 index4 alt2\">&nbsp;<\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c plain\">@Bean<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">public<\/code> <code class=\"c plain\">DataSource dataSource(){<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">DriverManagerDataSource dataSource = <\/code><code class=\"c keyword bold\">new<\/code> <code class=\"c plain\">DriverManagerDataSource();<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">dataSource.setUrl(<\/code><code class=\"c string\">\"jdbc:mysql:\/\/localhost:3306\/database_name\"<\/code><code class=\"c plain\">);<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">dataSource.setUsername( <\/code><code class=\"c string\">\"root\"<\/code> <code class=\"c plain\">);<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">dataSource.setPassword( <\/code><code class=\"c string\">\"root\"<\/code> <code class=\"c plain\">);<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">return<\/code> <code class=\"c plain\">dataSource;<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">}<\/code><\/div>\n<div class=\"line number14 index13 alt1\">&nbsp;<\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c plain\">@Bean<\/code><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">public<\/code> <code class=\"c plain\">LocalContainerEntityManagerFactoryBean entityManagerFactory() {<\/code><\/div>\n<div class=\"line number17 index16 alt2\">&nbsp;<\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">JpaVendorAdapter vendorAdapter = <\/code><code class=\"c keyword bold\">new<\/code> <code class=\"c plain\">HibernateJpaVendorAdapter(); <\/code><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">LocalContainerEntityManagerFactoryBean entityManager = <\/code><code class=\"c keyword bold\">new<\/code> <code class=\"c plain\">LocalContainerEntityManagerFactoryBean();<\/code><\/div>\n<div class=\"line number20 index19 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">entityManager.setJpaVendorAdapter(vendorAdapter);<\/code><\/div>\n<div class=\"line number21 index20 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">entityManager.setPackagesToScan(<\/code><code class=\"c string\">\"com.entity.package\"<\/code><code class=\"c plain\">);<\/code><\/div>\n<div class=\"line number22 index21 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">entityManager.setDataSource(dataSource());<\/code><\/div>\n<div class=\"line number23 index22 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">return<\/code> <code class=\"c plain\">entityManager;<\/code><\/div>\n<div class=\"line number24 index23 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c plain\">}<\/code><\/div>\n<div class=\"line number25 index24 alt2\">&nbsp;<\/div>\n<div class=\"line number26 index25 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c plain\">@Bean<\/code><\/div>\n<div class=\"line number27 index26 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">public<\/code> <code class=\"c plain\">PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {<\/code><\/div>\n<div class=\"line number28 index27 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">JpaTransactionManager txManager = <\/code><code class=\"c keyword bold\">new<\/code> <code class=\"c plain\">JpaTransactionManager();<\/code><\/div>\n<div class=\"line number29 index28 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">txManager.setEntityManagerFactory(entityManagerFactory);<\/code><\/div>\n<div class=\"line number30 index29 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">return<\/code> <code class=\"c plain\">txManager;<\/code><\/div>\n<div class=\"line number31 index30 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c plain\">}<\/code><\/div>\n<div class=\"line number32 index31 alt1\"><code class=\"c plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\">Configuration using xml file:<\/h2>\n<p>Similar to java code we can configure all necessary objects in xml file<\/p>\n<div>\n<div id=\"highlighter_188163\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">01<\/div>\n<div class=\"line number2 index1 alt1\">02<\/div>\n<div class=\"line number3 index2 alt2\">03<\/div>\n<div class=\"line number4 index3 alt1\">04<\/div>\n<div class=\"line number5 index4 alt2\">05<\/div>\n<div class=\"line number6 index5 alt1\">06<\/div>\n<div class=\"line number7 index6 alt2\">07<\/div>\n<div class=\"line number8 index7 alt1\">08<\/div>\n<div class=\"line number9 index8 alt2\">09<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<div class=\"line number20 index19 alt1\">20<\/div>\n<div class=\"line number21 index20 alt2\">21<\/div>\n<div class=\"line number22 index21 alt1\">22<\/div>\n<div class=\"line number23 index22 alt2\">23<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">&lt;bean id=<\/code><code class=\"c string\">\"entityManager\"<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"c spaces\">&nbsp;<\/code><code class=\"c keyword bold\">class<\/code><code class=\"c plain\">=<\/code><code class=\"c string\">\"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean\"<\/code><code class=\"c plain\">&gt; <\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;property name=<\/code><code class=\"c string\">\"dataSource\"<\/code> <code class=\"c keyword bold\">ref<\/code><code class=\"c plain\">=<\/code><code class=\"c string\">\"dataSource\"<\/code> <code class=\"c plain\">\/&gt;<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;property name=<\/code><code class=\"c string\">\"packagesToScan\"<\/code> <code class=\"c plain\">value=<\/code><code class=\"c string\">\"com.entity.package\"<\/code> <code class=\"c plain\">\/&gt;<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;property name=<\/code><code class=\"c string\">\"jpaVendorAdapter\"<\/code><code class=\"c plain\">&gt;<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;bean <\/code><code class=\"c keyword bold\">class<\/code><code class=\"c plain\">=<\/code><code class=\"c string\">\"org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter\"<\/code> <code class=\"c plain\">\/&gt; <\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;\/property&gt;<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"c spaces\">&nbsp;<\/code><code class=\"c plain\">&lt;\/bean&gt;<\/code><\/div>\n<div class=\"line number9 index8 alt2\">&nbsp;<\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"c plain\">&lt;bean id=<\/code><code class=\"c string\">\"dataSource\"<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">class<\/code><code class=\"c plain\">=<\/code><code class=\"c string\">\"org.springframework.jdbc.datasource.DriverManagerDataSource\"<\/code><code class=\"c plain\">&gt;<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;property name=<\/code><code class=\"c string\">\"url\"<\/code> <code class=\"c plain\">value=<\/code><code class=\"c string\">\"jdbc:mysql:\/\/localhost:3306\/database_name\"<\/code> <code class=\"c plain\">\/&gt;<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;property name=<\/code><code class=\"c string\">\"username\"<\/code> <code class=\"c plain\">value=<\/code><code class=\"c string\">\"root\"<\/code> <code class=\"c plain\">\/&gt;<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;property name=<\/code><code class=\"c string\">\"password\"<\/code> <code class=\"c plain\">value=<\/code><code class=\"c string\">\"root\"<\/code> <code class=\"c plain\">\/&gt;<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"c plain\">&lt;\/bean&gt;<\/code><\/div>\n<div class=\"line number16 index15 alt1\">&nbsp;<\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"c plain\">&lt;bean id=<\/code><code class=\"c string\">\"transactionManager\"<\/code> <code class=\"c keyword bold\">class<\/code><code class=\"c plain\">=<\/code><code class=\"c string\">\"org.springframework.orm.jpa.JpaTransactionManager\"<\/code><code class=\"c plain\">&gt;<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c plain\">&lt;property name=<\/code><code class=\"c string\">\"entityManagerFactory\"<\/code> <code class=\"c keyword bold\">ref<\/code><code class=\"c plain\">=<\/code><code class=\"c string\">\"entityManager\"<\/code> <code class=\"c plain\">\/&gt;<\/code><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"c plain\">&lt;\/bean&gt;<\/code><\/div>\n<div class=\"line number20 index19 alt1\">&nbsp;<\/div>\n<div class=\"line number21 index20 alt2\"><code class=\"c plain\">&lt;tx:annotation-driven \/&gt;<\/code><\/div>\n<div class=\"line number22 index21 alt1\"><code class=\"c plain\">&lt;bean id=<\/code><code class=\"c string\">\"persistenceExceptionTranslationPostProcessor\"<\/code> <code class=\"c keyword bold\">class<\/code><code class=\"c plain\">= <\/code><\/div>\n<div class=\"line number23 index22 alt2\"><code class=\"c string\">\"org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor\"<\/code> <code class=\"c plain\">\/&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3 class=\"wp-block-heading\">4) Inject the repository instance for use<\/h3>\n<p>Once all the above steps are done we are ready to use. Now we just need to instantiate and use&nbsp;use&nbsp;the interfaces.<\/p>\n<p>We can do that using spring basic features like dependency&nbsp;injection using @Autowired annotation.<\/p>\n<div>\n<div id=\"highlighter_600181\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c keyword bold\">class<\/code> <code class=\"c plain\">StudentService{ <\/code><\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;<\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"c plain\">@Autowired <\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"c keyword bold\">private<\/code> <code class=\"c keyword bold\">final<\/code> <code class=\"c plain\">StudentRepository studentRepository;<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code>&nbsp;<\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">public<\/code> <code class=\"c plain\">List&lt;Student&gt; findByDepartmentId(Long departmentId) {<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"c spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"c keyword bold\">return<\/code> <code class=\"c plain\">studentRepository.findByDepartmentId(departmentId);<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"c spaces\">&nbsp;&nbsp;<\/code><code class=\"c plain\">}<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"c plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\">Fast track reading<\/h2>\n<ul class=\"wp-block-list\">\n<li>Spring Data JPA is one of the most useful feature released by Spring team<\/li>\n<li>Using Sping data JPA repository implementation can be completely removed<\/li>\n<li>Can be used with core spring or spring boot application<\/li>\n<li>Should extend &nbsp;JPA specific Repository interface or it\u2019s&nbsp;sub interface<\/li>\n<li>Required method can be declared using meaningful name or using @Query annotation<\/li>\n<li>Configuration can be done using xml file or in java code<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">Related topics<\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/spring.io\/guides\/gs\/spring-boot\/\">Project setup for spring boot<\/a><\/li>\n<li><a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/docs\/2.3.0.RELEASE\/reference\/html\/#project\">Spring data website<\/a><\/li>\n<li><a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/docs\/2.3.0.RELEASE\/reference\/html\/#jpa.named-parameters\">JPA named parameters<\/a><\/li>\n<li><a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/docs\/2.3.0.RELEASE\/reference\/html\/#jpa.query-methods.query-creation\">Supported Keywords<\/a><\/li>\n<li><a href=\"https:\/\/www.javacodegeeks.com\/2020\/05\/spring-boot-custom-banner-generation.html\">Spring boot custom banner generation<\/a><\/li>\n<\/ul>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Stacktraceguru, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener noreferrer\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/stacktraceguru.com\/springboot\/spring-data-jpa\" target=\"_blank\" rel=\"noopener noreferrer\">Spring Boot Data JPA- beginner guide<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Databases form an integral part of computer applications. With it comes considerable amount of database operations and the corresponding code. For huge applications which have large number of tables\/entities, these operations or the code is repeated and duplicated to a large extent. Eventually a programmer would like to reduce this duplicate code. Spring framework took &hellip;<\/p>\n","protected":false},"author":116473,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[33,854,321],"class_list":["post-106338","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jpa","tag-spring-boot","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>Spring Boot Data JPA - beginner guide - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about Data JPA? Check our article presenting a beginners guide for Spring Boot Data JPA.\" \/>\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\/2020\/08\/spring-boot-data-jpa-beginner-guide.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot Data JPA - beginner guide - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about Data JPA? Check our article presenting a beginners guide for Spring Boot Data JPA.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.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:author\" content=\"www.facebook.com\/Stacktraceguru\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-18T04:00:04+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=\"Stacktraceguru\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Stacktraceguru\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html\"},\"author\":{\"name\":\"Stacktraceguru\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/08690a509ef2e0bc8bc98ddc16bb291d\"},\"headline\":\"Spring Boot Data JPA &#8211; beginner guide\",\"datePublished\":\"2020-08-18T04:00:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html\"},\"wordCount\":1213,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"JPA\",\"Spring Boot\",\"Spring Data\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html\",\"name\":\"Spring Boot Data JPA - beginner guide - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2020-08-18T04:00:04+00:00\",\"description\":\"Interested to learn about Data JPA? Check our article presenting a beginners guide for Spring Boot Data JPA.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.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\\\/2020\\\/08\\\/spring-boot-data-jpa-beginner-guide.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\":\"Spring Boot Data JPA &#8211; beginner guide\"}]},{\"@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\\\/08690a509ef2e0bc8bc98ddc16bb291d\",\"name\":\"Stacktraceguru\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/edc9a2f27fb2b63b35c4c626a71614ab39a609abb0ad59d73cfb2fa094d3ac4f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/edc9a2f27fb2b63b35c4c626a71614ab39a609abb0ad59d73cfb2fa094d3ac4f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/edc9a2f27fb2b63b35c4c626a71614ab39a609abb0ad59d73cfb2fa094d3ac4f?s=96&d=mm&r=g\",\"caption\":\"Stacktraceguru\"},\"description\":\"Stacktraceguru is an educational website. This website helps software programmers to learn and clarify concepts.\",\"sameAs\":[\"https:\\\/\\\/stacktraceguru.com\\\/\",\"www.facebook.com\\\/Stacktraceguru\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/stacktraceguru\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot Data JPA - beginner guide - Java Code Geeks","description":"Interested to learn about Data JPA? Check our article presenting a beginners guide for Spring Boot Data JPA.","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\/2020\/08\/spring-boot-data-jpa-beginner-guide.html","og_locale":"en_US","og_type":"article","og_title":"Spring Boot Data JPA - beginner guide - Java Code Geeks","og_description":"Interested to learn about Data JPA? Check our article presenting a beginners guide for Spring Boot Data JPA.","og_url":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"www.facebook.com\/Stacktraceguru\/","article_published_time":"2020-08-18T04:00:04+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":"Stacktraceguru","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Stacktraceguru","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html"},"author":{"name":"Stacktraceguru","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/08690a509ef2e0bc8bc98ddc16bb291d"},"headline":"Spring Boot Data JPA &#8211; beginner guide","datePublished":"2020-08-18T04:00:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html"},"wordCount":1213,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["JPA","Spring Boot","Spring Data"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html","url":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html","name":"Spring Boot Data JPA - beginner guide - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2020-08-18T04:00:04+00:00","description":"Interested to learn about Data JPA? Check our article presenting a beginners guide for Spring Boot Data JPA.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/spring-boot-data-jpa-beginner-guide.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\/2020\/08\/spring-boot-data-jpa-beginner-guide.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":"Spring Boot Data JPA &#8211; beginner guide"}]},{"@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\/08690a509ef2e0bc8bc98ddc16bb291d","name":"Stacktraceguru","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/edc9a2f27fb2b63b35c4c626a71614ab39a609abb0ad59d73cfb2fa094d3ac4f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/edc9a2f27fb2b63b35c4c626a71614ab39a609abb0ad59d73cfb2fa094d3ac4f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/edc9a2f27fb2b63b35c4c626a71614ab39a609abb0ad59d73cfb2fa094d3ac4f?s=96&d=mm&r=g","caption":"Stacktraceguru"},"description":"Stacktraceguru is an educational website. This website helps software programmers to learn and clarify concepts.","sameAs":["https:\/\/stacktraceguru.com\/","www.facebook.com\/Stacktraceguru\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/stacktraceguru"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/106338","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\/116473"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=106338"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/106338\/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=106338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=106338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=106338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}