{"id":1946,"date":"2019-09-02T12:00:00","date_gmt":"2019-09-02T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/hibernate-relationship-tutorial-onetomany-and-manytoone-part-21-to-8\/"},"modified":"2026-07-05T03:24:26","modified_gmt":"2026-07-05T01:24:26","slug":"hibernate-relationship-tutorial-onetomany-and-manytoone-part-21-to-8","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/hibernate-relationship-tutorial-onetomany-and-manytoone-part-21-to-8\/","title":{"rendered":"Hibernate Relationship Tutorial \u2013 @OneToMany and @ManyToOne (Part 21 to 28  )"},"content":{"rendered":"<p>We would continue from Part 21. You will learn how to update a record and delete a record. You will also learn about CascadeTypes and FetchTypes in Hibernate. So let&#8217;s get stated!<\/p>\n<ul>\n<li><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/hibernate-relationship-tutorial-onetomany-and-manytoone\/\">Part 1 to 7 &#8211; Setting Up<\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/hibernate-relationship-tutorial-onetomany-and-manytoone-part-8-to\/\">Part 8 to 12 &#8211; Infinite Recursion, @JoinColumn, JsonManagedReference etc<\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/hibernate-relationship-tutorial-onetomany-and-manytoone-part-13-to-16\/\">Part 13 to 16 &#8211; Retrieving Child Records<\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/hibernate-relationship-tutorial-onetomany-and-manytoone-part-17-to\/\">Part 17 to 20 &#8211; Inserting New Records. Using REST Client<\/a><\/li>\n<li><a href=\"#t21\">Part 21 &#8211; Updating Location Details<\/a><\/li>\n<li><a href=\"#t22\">Part 22 &#8211; Updating User Details<\/a><\/li>\n<li><a href=\"#t23\">Part 23 &#8211; Updating Post Details<\/a><\/li>\n<li><a href=\"#t24\">Part 24 &#8211; Deleting a Post<\/a><\/li>\n<li><a href=\"#t25\">Part 25 &#8211; Deleting a User<\/a><\/li>\n<li><a href=\"#t26\">Part 26 &#8211; CascadeTypes in Hibernate<\/a><\/li>\n<li><a href=\"#t27\">Part 27 &#8211; Deleting a Location<\/a><\/li>\n<li><a href=\"#t28\">Part 28 &#8211; FetchTypes in Hibernate<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong id=\"t21\">Part 21 &#8211; Updating Location Details<\/strong><\/p>\n<p>To update Location details, follows the steps below:<\/p>\n<p><strong>Step 1:<\/strong> Open the LocationController file<\/p>\n<p><strong>Step 2:<\/strong> Copy and paste the code below<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@PutMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/location\/{id}\/update\"<\/span><span style=\"color: #333333;\">)<\/span>\n<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;\">UpdateLocation<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@RequestBody<\/span> Location location<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n\tlocationService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">UpdateLocation<\/span><span style=\"color: #333333;\">(<\/span>location<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Open the LocationService and paste the code below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/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;\">UpdateLocation<\/span><span style=\"color: #333333;\">(<\/span>Location location<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n\tlocationRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">save<\/span><span style=\"color: #333333;\">(<\/span>location<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong> Launch the application. Use Advanced REST Client to attempt to update a location. Set the method this time to PUT<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t22\">Part 22 &#8211; Updating User Details<\/strong><\/p>\n<p>To update Location details, follows the steps below:<\/p>\n<p><strong>Step 1:<\/strong> Open the UserController file<\/p>\n<p><strong>Step 2:<\/strong> Copy and paste the code below<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@PutMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/user\/{id}\/update\"<\/span><span style=\"color: #333333;\">)<\/span>\n<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;\">UpdateUsern<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@RequestBody<\/span> User user <span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n\tuserService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">UpdateUser<\/span><span style=\"color: #333333;\">(user<\/span><span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Open the UserService and paste the code below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/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;\">UpdateUser<\/span><span style=\"color: #333333;\">(User user<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n\tuserRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">save<\/span><span style=\"color: #333333;\">(<\/span>user<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong> Relaunch and test<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t23\">Part 23 &#8211; Updating Post Details<\/strong><\/p>\n<p>To update Location details, follows the steps below:<\/p>\n<p><strong>Step 1:<\/strong> Open the PostController file<\/p>\n<p><strong>Step 2:<\/strong> Copy and paste the code below<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@PutMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/post\/{id}\/update\"<\/span><span style=\"color: #333333;\">)<\/span>\n<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;\">UpdatePost<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@RequestBody<\/span> Post post<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n\tpostService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">UpdatePost<\/span><span style=\"color: #333333;\">(<\/span>post<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Open the PostService and paste the code below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/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;\">UpdatePost<\/span><span style=\"color: #333333;\">(<\/span>Post post<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n\tpostRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">save<\/span><span style=\"color: #333333;\">(<\/span>post<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong> Relaunch and test<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t24\">Part 24: Deleting a Post<\/strong><\/p>\n<p>Deleting a Post would be quite straightforward as the Post object does not have any child objects. So let&#8217;s get it done!<\/p>\n<p><strong>Step 1:<\/strong> Copy the code below and paste in the PostController<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@DeleteMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/post\/{id}\/delete\"<\/span><span style=\"color: #333333;\">)<\/span>\n<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;\">DeletePost<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Integer id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n     postService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">DeletePost<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong> Copy the code below and paste into the PostService<\/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;\">DeletePost<\/span><span style=\"color: #333333;\">(<\/span>Integer id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n    postRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">deleteById<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Relaunch the application and test it using r the REST client. Either way, check that the post was deleted using H2 Console.<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t25\">Part 25: Deleting a User<\/strong><\/p>\n<p>The question about deleting a User is this: If we delete a particular user, what will happen to all the posts belonging to this user? Well, before we answer this question, let&#8217;s try to delete a user using the method used in deleting post.<\/p>\n<p><strong>Step 1:<\/strong> Copy the code below and paste in the UserController<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@DeleteMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/user\/{id}\/delete\"<\/span><span style=\"color: #333333;\">)<\/span>\n<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;\">DeleteUser<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Integer id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n     userService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">DeleteUser<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong> Copy the code below and paste into the UserService<\/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;\">DeleteUser<\/span><span style=\"color: #333333;\">(<\/span>Integer id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n    userRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">deleteById<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Relaunch the application and test it using\u00a0 REST client. Try to delete user\/1. You will notice that the delete operation fails. You receive a message like:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">{\n<span style=\"color: #007700;\">\"timestamp\"<\/span>: <span style=\"background-color: #fff0f0;\">\"2019-09-02T22:23:30.879+0000\"<\/span>,\n<span style=\"color: #007700;\">\"status\"<\/span>: <span style=\"color: #0000dd; font-weight: bold;\">500<\/span>,\n<span style=\"color: #007700;\">\"error\"<\/span>: <span style=\"background-color: #fff0f0;\">\"Internal Server Error\"<\/span>,\n<span style=\"color: #007700;\">\"message\"<\/span>: <span style=\"background-color: #fff0f0;\">\"could not execute statement; SQL [n\/a]; constraint [\"<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">FK<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">SF<\/span><span style=\"color: #0000dd; font-weight: bold;\">14<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">YOUCWQSO<\/span><span style=\"color: #0000dd; font-weight: bold;\">9<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">PDCH<\/span><span style=\"color: #0000dd; font-weight: bold;\">0<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">UIWPEM<\/span>: <span style=\"color: #ff0000; background-color: #ffaaaa;\">PUBLIC.POST<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">FOREIGN<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">KEY(USERID)<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">REFERENCES<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">PUBLIC.USER(ID)<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">(<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">)<\/span><span style=\"background-color: #fff0f0;\">\"; SQL statement: delete from user where id=? [23503-199]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement\"<\/span>,\n<span style=\"color: #007700;\">\"path\"<\/span>: <span style=\"background-color: #fff0f0;\">\"\/user\/1\/delete\"<\/span>\n}\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The reason for this error is that we try to delete a user who has posts.( an entity with child entities)<\/p>\n<p>Let&#8217;s now solve this problem by talking about CascadeTypes<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t26\">Part 26: CascadeType in Hibernate<\/strong><\/p>\n<p>The CascadeType answers the question of what will happen when you delete an object has children reference objects. Now a number of things could happen<\/p>\n<ul>\n<li>CascadeType.REMOVE: All the child entities are deleted (all post for the user is deleted)<\/li>\n<li>CascadeType.ALL: In this case, the operation is propagated from the parent to all the child entities<\/li>\n<li>CasCadeType.MERGE: It propagates merge operation from the parent to the child entities<\/li>\n<li>CascadeType.PERSIST: Here, the transient instance is made persistent<\/li>\n<li>CascadeType.DETACH: This cascade type removes that entity from the persistent context.<\/li>\n<\/ul>\n<p>Let&#8217;s not go to far! We&#8217;ll only use the second one: CascadeType.ALL<\/p>\n<p>To solve the problem simply take the step below:<\/p>\n<p><strong>Step 1:<\/strong> Open the User model<\/p>\n<p><strong>Step 2:<\/strong> Add cascade = CascadeType.ALL\u00a0 to the @OneToMany annotation. It would be as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@OneToMany<\/span><span style=\"color: #333333;\">(<\/span>mappedBy<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"user\"<\/span><span style=\"color: #333333;\">,<\/span> cascade <span style=\"color: #333333;\">=<\/span> CascadeType<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">ALL<\/span><span style=\"color: #333333;\">)<\/span>\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Post<span style=\"color: #333333;\">&gt;<\/span> posts<span style=\"color: #333333;\">;<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Step 3: Now try to repeat the delete operation and see that it works!<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Exercise:<\/strong> As an exercise for you, try out other CascadeTypes. Let me know in the comment box below the outcome<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t27\">Part 27 &#8211; Deleting a Location<\/strong><\/p>\n<p>This follows for the method for deleting a user.<\/p>\n<p><strong>Step 1:<\/strong> Copy the code below and paste in the LocationController<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@DeleteMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/location\/{id}\/delete\"<\/span><span style=\"color: #333333;\">)<\/span>\n<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;\">DeleteLocation<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Integer id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n     locationService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">DeleteLocation<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong> Copy the code below and paste into the LocationService<\/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;\">DeleteLocation<\/span><span style=\"color: #333333;\">(<\/span>Integer id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\n    locationRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">deleteById<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\n<span style=\"color: #333333;\">}<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong>\u00a0Open the User model, Add cascade = CascadeType.ALL\u00a0 to the @OneToMany annotation. It would be as shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #555555; font-weight: bold;\">@OneToMany<\/span><span style=\"color: #333333;\">(<\/span>mappedBy<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"location\"<\/span><span style=\"color: #333333;\">,<\/span> cascade <span style=\"color: #333333;\">=<\/span> CascadeType<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">ALL<\/span><span style=\"color: #333333;\">)<\/span>\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> List<span style=\"color: #333333;\">&lt;<\/span>User<span style=\"color: #333333;\">&gt;<\/span> users<span style=\"color: #333333;\">;<\/span>\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Step 3: Relaunch and try deleting a location. It works too.<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t28\">Part 28: FetchType in Hibernate<\/strong><\/p>\n<p>I would like to wrap up this course by talking about FetchTypes. This relates to how data is pulled from the repository &#8211; essentially from the database.<\/p>\n<p>We would focus on two types of FetchTypes: FetchType.EAGER and FetchType.LAZY<\/p>\n<p>FetchType.EAGER: This FetchType tells hibernate to retrieve the related record along with the initial query. This can be an advantage, but when the child entities to fetch is much, then it could create an overhead can jeopardize performance. For example, having to retrieve all the users in a location each time to access a Location.<\/p>\n<p>FetchType.LAZY: This can be used to tell hibernate to delay the initialization of the mapping until you access it explicitly.<\/p>\n<p>Do the following exercise:<\/p>\n<ul>\n<li><strong>Exercise 1:<\/strong> Add fetchType= FetchType.EAGER to all the @ManyToOne annotation<\/li>\n<li><strong>Exercise 2:<\/strong> Add fetchType=FetchType.LAZY\u00a0 to all the @OneToMany annotations<\/li>\n<li><strong>Exercise 3:<\/strong> Test the application with the FetchTypes.<\/li>\n<li><strong>Exercise 4:<\/strong> Remove all the FetchTypes and test the application again. Did you observe any change. Mention it in the comment box below.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Finally you made it to the end of this course. Thumbs up to you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We would continue from Part 21. You will learn how to update a record and delete a record. You will also learn about CascadeTypes and &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[414],"tags":[],"class_list":["post-1946","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1946"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1946\/revisions"}],"predecessor-version":[{"id":2114,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1946\/revisions\/2114"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}