Why does the "delete" not work as expected? Java, Spring MVC

0

The credential is simply not deleted, what am I doing wrong?

I am debugging and the credential that I want to delete if it exists, more when it does the "delete" is not deleted.

Controller method:

   @Autowired
    private CredentialDao credentialDao;
@RequestMapping(value = "/fisicHost/{id}/credentials", method = RequestMethod.POST)
public String deleteCredential(@PathVariable(value = "id") String credId){
    String[] parts = credId.split("-");
    int id = Integer.parseInt(parts[1]);
    Credential c = credentialDao.getCredentialById(id);
    credentialDao.delete(c);
    return "justreturnsomething";
}

CredentialDAO class, "delete" method:

@Override
public void delete(Credential credential) {
    Session session = sessionFactory.openSession();
    session.delete(credential);
    session.close();
}

Js of the front-end that makes the request:

$("#credentialsTable").on('click',"button[id^='del-']",  (e) => {
    var credentialId = e.target.id;
        console.log('credId' + credentialId);
        $.post( "/fisicHost/" + credentialId + "/credentials", data => {
        console.log(data);
    });
});

Debugging in IntelliJ I see that the credential that I wish to erase is the correct, attached image:

then by console it prints me the "justreturnsomething" but it does not erase the credential of the database ...

Photo from the BD:

the credential that I want to delete is the one with ID 3 !!!

    
asked by Nacho Zve De La Torre 21.11.2018 в 13:45
source

0 answers