title: How to get information from the both sides of @ManytoMany relationship?
body: <p>I'm new to JPA and I'm trying to build a @ManyToMany relationship between two entities: car.java and part.java.
  I wrote a method, which saves the relationship in a third table: car_part.</p>
  <p>car entity:</p>
  <pre><code> @ManyToMany(fetch = FetchType.EAGER)
      @JoinTable(name = &quot;car_part&quot;, joinColumns = @JoinColumn(name = &quot;car_id&quot;),
      inverseJoinColumns = @JoinColumn(name = &quot;part_id&quot;))
      private Set&lt;Part&gt; parts = new HashSet&lt;&gt;();
  </code></pre>
  <p>part entity:</p>
  <pre><code>@JsonIgnore
  @ManyToMany(mappedBy = &quot;parts&quot;)
  private Set&lt;Car&gt; cars = new HashSet&lt;&gt;();
  </code></pre>
  <p>car controller:</p>
  <pre><code>@PutMapping(&quot;/cars/{carId}/parts/{partId}&quot;)
      public Car addPartToCar(@PathVariable Long carId, @PathVariable Long partId) {
          
          Car car = carManager.findById(carId).get();
          Part part = partManager.findById(partId).get();
          
          car.addPart(part);
  
          return carManager.save(car);
      }
  </code></pre>
  <p>When I run a &quot;getCar&quot; method, a part is included:</p>
  <pre><code>{
      &quot;id&quot;: 3,
      &quot;brand&quot;: &quot;vw&quot;,
      &quot;numberPlate&quot;: &quot;12345&quot;,
      &quot;parts&quot;: [
          {
              &quot;id&quot;: 2,
              &quot;partName&quot;: &quot;part1&quot;,
              &quot;price&quot;: &quot;200&quot;
          }
      ]
  </code></pre>
  <p>But when I run a &quot;getPart&quot; method, a car is not included:</p>
  <pre><code>{
          &quot;id&quot;: 2,
          &quot;partName&quot;: &quot;part1&quot;,
          &quot;price&quot;: &quot;200&quot;
      }
  </code></pre>
  <p>My Question: Why is a car not included, when I'm searching for a part?
  I searched and I found out, I should add the relationship to the both sides. So I should probably add a car to the part like this, but I'm getting a LazyInitializationException</p>
  <pre><code>@PutMapping(&quot;/cars/{carId}/parts/{partId}&quot;)
      public Car addPartToCar(@PathVariable Long carId, @PathVariable Long partId) {
  
          Car car = carManager.findById(carId).get();
          Part part = partManager.findById(partId).get();
  
          car.addPart(part);
          part.getCars().add(car);
  
          partManager.save(part);
  
          return carManager.save(car);
  
      }
  </code></pre>
  <p>Any help you can give would be greatly appreciated.</p>
  <p>UPDATE:
  I removed @JsonIgnore but now I get the HttpMessageNotWritableException</p>