Can´t delete with JPA native query

Viewed 47

I´m trying to delete a row from a mysql table ( registros ) with jpa, but the query is not working. Testing with postman deliver 500 error, fixed ( for testing only ) using return(null) in the PostMapping. Test again, no error, but the record in the database is still here.

What im doing wrong?

Interface for the query :

public interface Eliminar extends JpaRepository<registros, Long> {
  

    @Modifying(clearAutomatically = true, flushAutomatically = true)
    @Query (value = "DELETE FROM registros WHERE ID like :id", nativeQuery = true)
    List<registros> borrarreg(@Param("id") Long id) ;
}

PostMapping that call the "borrareg" method:

private Eliminar borrarregistro;
               @PostMapping(path="borrarreg")
               public @ResponseBody List<registros> borrarreg(@RequestParam Long id) 
               {
                 return borrarregistro.borrarreg(id);
                 }  

Model registros ( database ):

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;



@Entity
@Table(name ="registros")
public class registros {
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)

    private int id ;
    private int numerocliente ;
    private String nombrecliente ;
    private String maccpe ;
    private String direccionip ;





public int getId() {
    return id;
}

public int getnumerocliente() {
    return numerocliente;
}
public void setnumerocliente(int numerocliente) {
    this.numerocliente = numerocliente;
}
public String getnombrecliente() {
    return nombrecliente;
}
public void setnombrecliente(String nombrecliente) {
    this.nombrecliente = nombrecliente;
}
public String getmaccpe() {
    return maccpe;
}
public void setmaccpe(String maccpe) {
    this.maccpe = maccpe;
}
public String getdireccionip() {
    return direccionip;
}
public void setdireccionip(String direccionip) {
    this.direccionip = direccionip;
}




}

Crud interface for add:

import org.springframework.data.repository.CrudRepository;
import bookip.demo.models.registros;



public interface Registros extends CrudRepository<registros, Integer> {
}

Add, and search methods work with no problem. Only delete is not working.

Thanks in advance

0 Answers
Related