Error Request method 'GET' not supported while performing update

Asked

Viewed 1,128 times

-2

Good colleagues. I have a mistake I haven’t solved yet. I wanted to create a feature in my application that I am developing with spring mvc. The goal was to click the button or link it changes the state field that accepts only two Allowed and Not Allowed values from a table called User to Not Allowed. So first I created a method in the DAO layer to use the jpql query to perform the update, the method is as follows:

@Override
    public void interdict() {
        createJpqlQuery("update Utente set estado='Não permitido'");

    }

Then I created the method in the service layer:

@Transactional(readOnly = true)
@Override
    public void interditarUtentes() {
        utenteDAO.interdict();

    }

Then I called the service layer method for the controller

@PostMapping("/interditar")
    public String interditarUtentes(ModelMap model, RedirectAttributes attr) {
        System.out.println("AQUIIIII");
        service.interditarUtentes();    
        attr.addFlashAttribute("success", "Utentes registados interditos com sucesso");
        return "redirect:/utente/listar";   
    }

But when I call the controller from the page returns the following error:

Request method 'GET' not supported
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported

I tried to use @Requestmapping where I used the value and method parameters and gave the same error.

I tried to exchange post for get and also gives another different error that was: 

There was an unexpected error (type=Internal Server Error, status=500).
org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [update mz.com.centropontoencontro.domain.Utente set estado='Não permitido']; nested exception is java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [update mz.com.centropontoencontro.domain.Utente set estado='Não permitido']
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [update mz.com.centropontoencontro.domain.Utente set estado='Não permitido']; nested exception is java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [update mz.com.centropontoencontro.domain.Utente set estado='Não permitido']

The Domain class of the object is:

@Entity
@Table(name = "ute_utente")
public class Utente {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ute_id")
    private Long id;

    @Column(name = "ute_nome")
    private String nome;

    @Column(name = "ute_datanascimento")
    @DateTimeFormat(iso = ISO.DATE)
    private LocalDate dataNascimento;

    @Column(name = "ute_genero")
    private String genero;

    @Column(name = "ute_naturalidade")
    private String naturalidade;

    @Column(name = "ute_bi")
    private String numeroBi;

    @Column(name = "ute_nomemae")
    private String nomeMae;

    @Column(name = "ute_nomepai")
    private String nomePai;

    @Column(name = "ute_localtrabalho")
    private String localTrabalho;

    @Column(name = "ute_contacto")
    private String contacto;

    @Column(name = "ute_estado")
    private String estado;

    @Column(name = "ute_numeroemps")
    private Long numeroEmprestimos;

    @Column(name = "ute_data_registo", nullable = false)
    private LocalDateTime dataRegisto;

    @ManyToOne
    @JoinColumn(name = "ute_instituicaoid")
    private InstituicaoEnsino instituicaoEnsino;

    @JoinColumn(name = "ute_enderecoid")
    @OneToOne(cascade = CascadeType.ALL)
    private Endereco endereco;

What should I do?

  • Post instead of GET, your controller is using @PostMapping, if you want to use GET switch to @GetMapping

  • I suggest closing the question and creating a new one, since the original problem has been fixed

  • thank you. After switching to @Getmapping released another error: Caused by: org.hibernate.hql.internal.Queryexecutionrequestexception: Not supported for DML Operations [update mz.com.centropontoencontro.domain.Utente set status='Not allowed']

  • As I said, the initial problem was closed, I suggest opening a new question

1 answer

1


The problem is calling a method that only accepts POST (method marked as @PostMapping) using GET.

If the idea is really to use GET, just note the method as @GetMapping.

Link to documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.