title: Pagination in spring boot looping the association data
body: <p>Hi i am trying to implement pagination in spring boot. i have 3 tables.</p>
  
  <p>1) Post -> Which store the post like small tweets.</p>
  
  <p>2) Profile -> User details </p>
  
  <p>3) Authentication -> User's Authentication table.</p>
  
  <p>The Relationship between these 3 tables are as follows.</p>
  
  <pre><code> profile have OneToOne relation with Authentication.  
   profile have OneToMany relation with Post.
  
   authentication have OneToOne with Profile.
  
   Post have OneToOne with Profile.
  </code></pre>
  
  <p>When i am trying the Pagination as follows for the post table </p>
  
  <p><strong>Post.java</strong>  </p>
  
  <pre><code> @Entity
   public class Post {
  
       @OneToOne(fetch = FetchType.LAZY)
       private Profile profile;
  
       @Override
       public String toString() {
            return "Post [id=" + id + ", tweet=" + tweet + ", profile=" + profile + "]";
  }
  </code></pre>
  
  <p><strong>PostRepository.Java</strong></p>
  
  <pre><code> @Repository
    public interface PostRepository extends PagingAndSortingRepository&lt;Post,Integer&gt; {
        Post findById(int id);
    }
  </code></pre>
  
  <p><strong>PersonPagingService .Java</strong></p>
  
  <pre><code> public interface PersonPagingService {
  
  Page&lt;Post&gt; getAllPosts(Pageable pageable);
  
  }
  </code></pre>
  
  <p><strong>PostService.Java</strong>     </p>
  
  <pre><code>@Service
  public class PostService implements PersonPagingService {
  
      @Autowired
      private PostRepository postRepository;
  
      @Override
      public Page&lt;Post&gt; getAllPosts(Pageable pageable){
          return postRepository.findAll(pageable);
      }
  }
  </code></pre>
  
  <p><strong>PostController.Java</strong>'</p>
  
  <pre><code>@RestController
  public class PostController{
  
      @GetMapping("/test")
      public List&lt;Post&gt; checkThesSignupEmailIsNew(Pageable pageable) {
         Page&lt;Post&gt; posts = PersonPagingService.getAllPosts(pageable);
         return posts.getContent();
      }
  } 
  </code></pre>
  
  <p>When i am sending the request for </p>
  
  <p><a href="https://i.stack.imgur.com/NMZme.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NMZme.png" alt="enter image description here"></a></p>
  
  <p>Raw Data</p>
  
  <p><a href="https://i.stack.imgur.com/6CJSq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6CJSq.png" alt="RAW DATA of response"></a></p>
  
  <p><strong><em>If i am deleting the Relationship in POST.JAVA then it's working fine.</em></strong></p>
  
  <p>Please help me to understand what mistake i am doing.</p>
  
  <p>**don't worry about authentication data it's test data **</p>
  
  <p><strong>Profile.Java</strong></p>
  
  <pre><code>@Entity
   public class Profile {
  
    @OneToMany(fetch=FetchType.LAZY, cascade= CascadeType.ALL, mappedBy = "profile")
    List&lt;Post&gt; posts; 
  
     @Override
     public String toString() {
      return "Profile [id=" + id + ", name=" + name + ", email=" + email + ", location=" + location + "]";
     }
  }
  </code></pre>
  
  <p>It Fetching one Post From the database </p>
  
  <pre><code>[![one Post][3]][3]  
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/gO7uh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gO7uh.png" alt="enter image description here"></a></p>