1

I am trying to delete a row by using deleteById method of CrudRepository and It is not working/deleting the row. I enabled the hibernate log to see the generated queries by hibernate. For deleteById method :- It is only generating select query but not the delete query. anyone ever encountered this issue ? I also tried different dervied delete method. It's same response from Hibernate. But for different method like find it is working fine and generating the select query.is I am missing anything fundamental here?

My Entity Class:-

@Entity
public class Application {

    @Id
    @GeneratedValue
    private Long id;

    @OneToOne(cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Employee employee;

    @OneToOne(cascade = {CascadeType.ALL}, orphanRemoval = true)
    private Employer employer;

    @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, orphanRemoval = true)
    private Data data;

    @OneToOne
    @PrimaryKeyJoinColumn
    private Reports reports;
    
    //Getter & Setters
}

My Application Repository :-

@Repository
public interface ApplicationRepository extends JpaRepository<Application, Long> {

}

My Application Service method :-

@Transactional
public void deleteApplicationData(Long applicationId) {
        applicationRepo.deleteById(applicationId);
}
Bishal Dubey
  • 150
  • 7
  • It is doing a findById first that is why you see Select query. It might be that it is not finding it in your database, that is why it is not triggering Delete afterwards. See also: https://stackoverflow.com/questions/67150443/spring-data-jpa-repository-deletebyid-method-not-working – JCompetence Nov 12 '21 at 12:14
  • maybe dublicate: https://stackoverflow.com/questions/22688402/delete-not-working-with-jparepository – Mustafa Çil Nov 12 '21 at 13:23

0 Answers0