title: My repository is not called in my service - Spring Data JPA
body: <p>I don't understand why my weight record Repository is not called in spite of my code. I have written some logs before and after the weight record repository call. In my console, I can see that logs are called before and after, but not my repository. I have a code 200 OK, but in my database, my data is always here. I don't understand why. My Tomcat port is set to port 7777. I can create and read data but not delete it.</p>
  <p>Just below my code : ENTITY, CONTROLLER, REPOSITORY and SERVICE.</p>
  <p><a href="https://gitlab.com/genetquentin/openweighttracker_backend/-/tree/develop" rel="nofollow noreferrer">https://gitlab.com/genetquentin/openweighttracker_backend/-/tree/develop</a></p>
  <pre><code>/*ENTITY 'PERSON'*/
  @Entity
  @Table(name = &quot;person&quot;)
  public class Person implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = &quot;id_person&quot;)
      private Long idPerson;
  
      @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;id_initial_data&quot;)
      private InitialData userInitData;
  
      @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;id_user&quot;)
      private AppUser appUserPerson;
      
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = &quot;person&quot;)
      private List&lt;WeightRecord&gt; weightsList = new ArrayList&lt;WeightRecord&gt;();
      
      /* Getters and setters */
  
  
  
        /*ENTITY 'WEIGHTRECORD'*/
  
          @Entity
          @Table(name = &quot;weight_record&quot;)
          public class WeightRecord implements Serializable{
          
              private static final long serialVersionUID = 1L;
          
              @Id
              @GeneratedValue(strategy = GenerationType.IDENTITY)
              @Column(name = &quot;id_weight_record&quot;)
              private Long idWeightRecord;
              
              @Column(name = &quot;weight_record_date&quot;, nullable = true)
              private LocalDate weightRecordDate;
          
              //JsonIgnore annotation because circular problem with Jackson and entity.
              @JsonIgnore
              @ManyToOne
              private Person person;
              
              @Min(1)
              @Max(635)
              @Column(name = &quot;weight_kg_record&quot;, nullable = true, precision = 1)
              private Double weightKgRecord;
          
              @Min(1)
              @Max(99)
              @Column(name = &quot;percent_fat_mass&quot;, nullable = true, precision = 1)
              private Double percentFatMass;
          
              @Min(1)
              @Max(99)
              @Column(name = &quot;percent_muscular_mass&quot;, nullable = true, precision = 1)
              private Double percentMuscularMass;
          
              @Min(1)
              @Max(99)
              @Column(name = &quot;percent_body_water&quot;, nullable = true, precision = 1)
              private Double percentBodyWater;
          
              @Min(1)
              @Max(99)
              @Column(name = &quot;percent_bone_mass&quot;, nullable = true, precision = 1)
              private Double percentBoneMass
          
              /* Getters and setters */
          
      
      
              /*CONTROLLER*/    
                  @CrossOrigin(origins = &quot;*&quot;)
                  @RestController
                  @RequestMapping(&quot;/weights&quot;)
                  public class WeightRecordController {
                  
                      @Autowired
                      WeightRecordServiceImpl weightRecordServiceImpl;
                  
                      @Autowired
                      WeightRecordRepository weightRecordRepository;
                  
                      @Autowired
                      AppUserRepository appUserRepository;
                  
                      @Autowired
                      PersonRepository personRepository;
                  
                      private final Logger logger = LoggerFactory.getLogger(WeightRecordController.class);
                  
                      
                      //TODO : Weight is not deleted  and repository not called ?
                      // USE deleteinbatch method repository from jpa ?
                      @DeleteMapping(&quot;/{weightId}&quot;)
                      public ResponseEntity&lt;WeightRecord&gt; deleteWeigthById(@PathVariable(&quot;weightId&quot;) Long weightId, Principal principal) {
                          logger.info(&quot;DELETE /weights/{}&quot;, weightId);
                          try {
                              
                              Long appUserConnectedId = this.getAppUserConnectedId(principal);
                              Person personConnected = personRepository.findById(appUserConnectedId).orElseThrow();
                              WeightRecord weightRecordToDelete = weightRecordRepository.findById(weightId).orElseThrow();
                              
                              if(personConnected != null &amp;&amp; personConnected.getWeightsList().contains(weightRecordToDelete)) {
                                  logger.info(&quot;SERVICE FOR DELETING&quot;);
                                  logger.info(weightRecordToDelete.getWeightKgRecord().toString());
                                  return ResponseEntity.ok(weightRecordServiceImpl.deleteWeightById(weightId));
                              } else {
                                  logger.info(&quot;BAD USER FOR BAD WEIGHT&quot;);
                                  return ResponseEntity.notFound().build();
                              }
                          } catch (NoSuchElementException nse) {
                              return ResponseEntity.notFound().build();
                          }   
                      }
                  }
              
      
      
      /*REPOSITORY*/
      
              
                  @Repository
                  public interface WeightRecordRepository extends JpaRepository&lt;WeightRecord, Long&gt; {
                  }
              
              
      
      
      /*SERVICE*/
              
              @Service
              public class WeightRecordServiceImpl implements WeightRecordService {
              
                  @Autowired
                  WeightRecordRepository weightRecordRepository;
              
                  @Autowired
                  AppUserRepository appUserRepository;
              
                  @Autowired
                  PersonRepository personRepository;
              
                  private final Logger logger = LoggerFactory.getLogger(WeightRecordServiceImpl.class);
              
                  public WeightRecord deleteWeightById(Long weightRecordToDeleteId) {
                      
                      logger.info(&quot;THIS IS THE WEIGHT ID TO DELETE : {}&quot;, weightRecordToDeleteId);
                      WeightRecord weightRecordToDelete = weightRecordRepository.findById(weightRecordToDeleteId).orElseThrow();
                      weightRecordRepository.deleteById(weightRecordToDeleteId);
                      logger.info(&quot;Weight with id n°{} is deleted now&quot;, weightRecordToDelete.getIdWeightRecord());
                      return weightRecordToDelete;
                  }
          
  </code></pre>
  <p>My request in Insomnia:<br />
  <a href="https://i.stack.imgur.com/A2fsF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A2fsF.png" alt="My request in Insomnia" /></a></p>
  <p>Result of request in console:<br />
  <a href="https://i.stack.imgur.com/n3bP8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n3bP8.png" alt="Result of request in console" /></a></p>