{"id":126,"date":"2019-03-13T06:24:07","date_gmt":"2019-03-13T06:24:07","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/spring-boot\/?p=126"},"modified":"2019-03-14T13:35:25","modified_gmt":"2019-03-14T13:35:25","slug":"16-spring-boot-crud-operation-with-jpa-repository","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/","title":{"rendered":"Spring Boot &#8211; CRUD Operation with JPA Repository"},"content":{"rendered":"<p>In this chapter, we are going to learn how to make CRUD operation using JPA repository.\u00a0 As mentioned before, the repository provides methods to perform these operations.The only file we need to modify is the StudentService file.<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li><a href=\"#t1\">Modify the Repository<\/a><\/li>\n<li><a href=\"#t2\">Autowire the Repository into the Service<\/a><\/li>\n<li><a href=\"#t3\">Get List of Students<\/a><\/li>\n<li><a href=\"#t4\">Add a Student<\/a><\/li>\n<li><a href=\"#t5\">Get Student by Id<\/a><\/li>\n<li><a href=\"#t6\">Update a Student Record<\/a><\/li>\n<li><a href=\"#t7\">Delete a Student<\/a><\/li>\n<li><a href=\"#t8\">Build the StudentController class<\/a><\/li>\n<li><a href=\"#t9\">Handling Errors<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t1\">1. Modify the Repository<\/strong><\/h4>\n<p>Let&#8217;s open the StudentRepository and make a little change. We should actually have done this in the previous chapter. The modified class is shown below.<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> com<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">kindsonthegenius<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">social<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">student<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.data.repository.CrudRepository<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">interface<\/span> <span style=\"color: #bb0066; font-weight: bold;\">StudentRepository<\/span> <span style=\"color: #008800; font-weight: bold;\">extends<\/span> CrudRepository<span style=\"color: #333333;\">&lt;<\/span>Student<span style=\"color: #333333;\">,<\/span> String<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Note the we have provided the Student and String.The Student is the entity type while the String is the primary key type.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t2\">2. AutoWire the Repository into the Service<\/strong><\/h4>\n<p>The very first step is to AutoWire the StudentRepository into the Student Service. So open the StudenRepository class. Create a private member variable of StudentReposiory. Then add @Autowired to this variable. If you do this, the StudentService class would be as shown below:<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> com<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">kindsonthegenius<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">social<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">student<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.beans.factory.annotation.Autowired<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.stereotype.Service<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #555555; font-weight: bold;\">@Service<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">StudentService<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\r\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> StudentRepository studentRepository<span style=\"color: #333333;\">;<\/span>\r\n\t\r\n    <span style=\"color: #888888;\">\/\/ The Crud methods goes here<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t3\">3. Get List of Students<\/strong><\/h4>\n<p>First, we get a list of Students. To do that we use the<strong> findAll()<\/strong> method.So this means that we can use a single line as shown below to get all records.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">studentRepository.<span style=\"color: #0000cc;\">findAll<\/span>();\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>This one line is all is needed to connect to do the following:<\/p>\n<ul>\n<li>connect to the database<\/li>\n<li>run a query to get all the Student records<\/li>\n<li>convert each of the returned rows to Student instances<\/li>\n<li>return it back to the service<\/li>\n<\/ul>\n<p>The findAll() method returns an iterable. So we need to convert it into a list. The complete code is given below:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Student<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getAllStudents<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\r\n    List<span style=\"color: #333333;\">&lt;<\/span>Student<span style=\"color: #333333;\">&gt;<\/span> students <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> ArrayList<span style=\"color: #333333;\">&lt;&gt;();<\/span>\r\n\t\r\n    studentRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findAll<\/span><span style=\"color: #333333;\">()<\/span>\r\n    <span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">forEach<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #997700; font-weight: bold;\">students:<\/span><span style=\"color: #333333;\">:<\/span>add<span style=\"color: #333333;\">);<\/span>\r\n\t\r\n    <span style=\"color: #008800; font-weight: bold;\">return<\/span> students<span style=\"color: #333333;\">;<\/span>\t\t\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>What we do here is that we created an empty list of Student. Then we iterate through the list returned by findAll(). For each item in the list, we add it to the students list we created. We have used a method reference here (::). We could actually test this method now. However, we&#8217;ve not populated our controller class. Besides, there is nothing in the database. So we would have an empty result. So the next thing to do is to add a method to add new Student.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t4\">4. Add a Student<\/strong><\/h4>\n<p>To add a new Student is really easy. You do this by using the StudentRepository <em><strong>save()<\/strong><\/em> method. You simply pass it as parameter, the Student instance you want to save.<\/p>\n<p>The method is given below.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">addStudent<\/span><span style=\"color: #333333;\">(<\/span>Student student<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n     studentRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">save<\/span><span style=\"color: #333333;\">(<\/span>student<span style=\"color: #333333;\">);<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t5\">5. Get Student by Id<\/strong><\/h4>\n<p>Again, the StudentRepository provides a method findById(). This methods takes the id of the Student to find. This method use to be findOne(). But since Spring data jpa 2.0 it&#8217;s changed to findById(). Also note the Optional keword. This is there to prevent nullPointerException in case the record is not found.<\/p>\n<p>The code snipped is given below:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> Optional<span style=\"color: #333333;\">&lt;<\/span>Student<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getStudent<\/span><span style=\"color: #333333;\">(<\/span>String id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n     <span style=\"color: #008800; font-weight: bold;\">return<\/span> studentRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findById<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t6\">6. Update a Student<\/strong><\/h4>\n<p>To update a Student record, we used the same save() method as with adding a new Student.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">updateStudent<\/span><span style=\"color: #333333;\">(<\/span>String id, Student student<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n     studentRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">save<\/span><span style=\"color: #333333;\">(<\/span>student<span style=\"color: #333333;\">);<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>This is what happens with update: if the record exists, then it is updates. If however, the record with the id does not exist, then it adds a new record.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t7\">7. Delete a Student<\/strong><\/h4>\n<p>To delete a Student record, you simply use the deleteById() method provided by the StudentRepository. The you pass in the id of the record you want to delete.<\/p>\n<p>The code is given below:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">deleteStudent<\/span><span style=\"color: #333333;\">(<\/span>String id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n     studentRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">deleteById<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t8\">8. Build the Controller Class<\/strong><\/h4>\n<p>Now we are going to write out controller methods in the controller class. It is fairly easy. It&#8217;s exacly similar to the other controllers we&#8217;ve written. So I would just provide you with the code as shown below:<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@RestController<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">StudentController<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\r\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> StudentService studentService<span style=\"color: #333333;\">;<\/span>\r\n\r\n\t <span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\/students\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t   <span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Student<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getAllStudents<\/span><span style=\"color: #333333;\">()<\/span> \r\n\t   <span style=\"color: #333333;\">{<\/span>\t\t\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> studentService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getAllStudents<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t   <span style=\"color: #333333;\">}<\/span>\t\r\n\t \r\n\t \r\n\t <span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\/students\/{id}\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t <span style=\"color: #008800; font-weight: bold;\">public<\/span> Optional<span style=\"color: #333333;\">&lt;<\/span>Student<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getStudent<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> String id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t \t<span style=\"color: #008800; font-weight: bold;\">return<\/span> studentService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getStudent<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\r\n\t <span style=\"color: #333333;\">}<\/span>\r\n\t \r\n\t \r\n\t <span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\/students\"<\/span><span style=\"color: #333333;\">,<\/span> method<span style=\"color: #333333;\">=<\/span>RequestMethod<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">POST<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t <span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">addStudent<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@RequestBody<\/span> Student student<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t studentService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">addStudent<\/span><span style=\"color: #333333;\">(<\/span>student<span style=\"color: #333333;\">);<\/span>\r\n\t <span style=\"color: #333333;\">}<\/span>\r\n\t \r\n\t <span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\/students\/{id}\"<\/span><span style=\"color: #333333;\">,<\/span> method <span style=\"color: #333333;\">=<\/span> RequestMethod<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">PUT<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t <span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">updateStudent<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@RequestBody<\/span> Student student<span style=\"color: #333333;\">,<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> String id <span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t studentService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">updateStudent<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">,<\/span> student<span style=\"color: #333333;\">);<\/span>\r\n\t <span style=\"color: #333333;\">}<\/span>\r\n\t \r\n\t <span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\/students\/{id}\"<\/span><span style=\"color: #333333;\">,<\/span> method <span style=\"color: #333333;\">=<\/span> RequestMethod<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">DELETE<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t <span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">deleteStudent<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> String id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t studentService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">deleteStudent<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\r\n\t\t \t \r\n\t <span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Note that the code above does not include the import statements and package name. So remember to add them.<\/p>\n<p>Now is time to test everything. So open Advanced Rest Client. Add a few student record. The make GET, UPDATE and DELETE requests to see how it works.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id = \"t9\">9. Handling Errors<\/strong><\/h4>\n<p>If you follow these procedures correctly, you may receive some errors. To handle them do the following<\/p>\n<p>&nbsp;<\/p>\n<p><strong>add a default constructor<\/strong><\/p>\n<p>Open the Student class and add a default empty constructor. As shown below:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #0066bb; font-weight: bold;\">Student<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n    <span style=\"color: #888888;\">\/\/nothing goes here<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>modify the properties file<\/strong><\/p>\n<p>Open the application.properties file and add the following line:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">spring<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jpa<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">hibernate<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">ddl<\/span><span style=\"color: #333333;\">-<\/span>auto<span style=\"color: #333333;\">=<\/span>update\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>If you recieve any further error after doing these steps, let us know in the comment box below.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>In this chapter, we are going to learn how to make CRUD operation using JPA repository.\u00a0 As mentioned before, the repository provides methods to perform &hellip; <!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":132,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Boot - CRUD Operation with JPA Repository - Learn Spring Boot<\/title>\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.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot - CRUD Operation with JPA Repository - Learn Spring Boot\" \/>\n<meta property=\"og:description\" content=\"In this chapter, we are going to learn how to make CRUD operation using JPA repository.\u00a0 As mentioned before, the repository provides methods to perform &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn Spring Boot\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-13T06:24:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-14T13:35:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Crud-Operations-With-JPA-Repository.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"781\" \/>\n\t<meta property=\"og:image:height\" content=\"451\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"headline\":\"Spring Boot &#8211; CRUD Operation with JPA Repository\",\"datePublished\":\"2019-03-13T06:24:07+00:00\",\"dateModified\":\"2019-03-14T13:35:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/\"},\"wordCount\":747,\"commentCount\":13,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2019\\\/03\\\/Crud-Operations-With-JPA-Repository.jpg\",\"articleSection\":[\"Spring Boot Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/\",\"name\":\"Spring Boot - CRUD Operation with JPA Repository - Learn Spring Boot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2019\\\/03\\\/Crud-Operations-With-JPA-Repository.jpg\",\"datePublished\":\"2019-03-13T06:24:07+00:00\",\"dateModified\":\"2019-03-14T13:35:25+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2019\\\/03\\\/Crud-Operations-With-JPA-Repository.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2019\\\/03\\\/Crud-Operations-With-JPA-Repository.jpg\",\"width\":781,\"height\":451},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/16-spring-boot-crud-operation-with-jpa-repository\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Boot &#8211; CRUD Operation with JPA Repository\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/\",\"name\":\"Learn Spring Boot\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot - CRUD Operation with JPA Repository - Learn Spring Boot","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.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/","og_locale":"en_US","og_type":"article","og_title":"Spring Boot - CRUD Operation with JPA Repository - Learn Spring Boot","og_description":"In this chapter, we are going to learn how to make CRUD operation using JPA repository.\u00a0 As mentioned before, the repository provides methods to perform &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/","og_site_name":"Learn Spring Boot","article_published_time":"2019-03-13T06:24:07+00:00","article_modified_time":"2019-03-14T13:35:25+00:00","og_image":[{"width":781,"height":451,"url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Crud-Operations-With-JPA-Repository.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"headline":"Spring Boot &#8211; CRUD Operation with JPA Repository","datePublished":"2019-03-13T06:24:07+00:00","dateModified":"2019-03-14T13:35:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/"},"wordCount":747,"commentCount":13,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Crud-Operations-With-JPA-Repository.jpg","articleSection":["Spring Boot Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/","name":"Spring Boot - CRUD Operation with JPA Repository - Learn Spring Boot","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Crud-Operations-With-JPA-Repository.jpg","datePublished":"2019-03-13T06:24:07+00:00","dateModified":"2019-03-14T13:35:25+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Crud-Operations-With-JPA-Repository.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Crud-Operations-With-JPA-Repository.jpg","width":781,"height":451},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/16-spring-boot-crud-operation-with-jpa-repository\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/spring-boot\/"},{"@type":"ListItem","position":2,"name":"Spring Boot &#8211; CRUD Operation with JPA Repository"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#website","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/","name":"Learn Spring Boot","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/spring-boot\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/author\/kindsonthegenius-3\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":3,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":133,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/126\/revisions\/133"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/media\/132"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}