1
resposta

Após mudar a classe UsuarioDaoImpl.java não consigo registrar novos usuários

HTTP Status 500 – Internal Server Error
Type Exception Report

Message Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:979)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
1 resposta

Oi Paulo, a sua classe UsuarioDaoImpl ficou conforme abaixo? Pela mensagem de erro a instrução sql pode estar errada

@Repository
public class UsuarioDaoImpl implements UsuarioDao {

    @PersistenceContext
    private EntityManager manager;

    public void salva(Usuario usuario) {
        manager.persistence(usuario);
    }

    public Usuario procuraUsuario(Usuario usuario) {
       TypedQuery<Usuario> query= manager
            .createQuery("select u from Usuario u where u.email=:email and u.senha=:senha", Usuario.class);
        query.setParameter("email", usuario.getEmail());
        query.setParameter("senha", usuario.getSenha());

        Usuario usuarioRetornado = query.getResultList().stream().findFirst().orElse(null);
        return usuarioRetornado;
    }
}

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software