Problem while doing an update

Asked

Viewed 1,469 times

0

Well I’m having difficulty to perform an update on my database it is presenting the following Exception.

ERROR [org.springframework.security.web.Authentication.Usernamepasswordauthenticationfilter] (default task-11) An Internal error occurred while trying to authenticate the user.: org.springframework.security.authentication.Internalauthenticationserviceexception: Row was updated or Deleted by Another transaction (or Unsaved-value Mapping was incorrect) : [br.com.netservicos.sic.model.Folha#61] at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(Daoauthenticationprovider.java:127) at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(Abstractuserdetailsauthenticationprovider.java:144) at org.springframework.security.authentication.Providermanager.authenticate(Providermanager.java:174) at org.springframework.security.authentication.Providermanager.authenticate(Providermanager.java:199) at org.springframework.security.web.Authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(Usernamepasswordauthenticationfilter.java:94) at org.springframework.security.web.Authentication.AbstractAuthenticationProcessingFilter.doFilter(Abstractauthenticationprocessingfilter.java:218) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:331) at org.springframework.security.web.Authentication.logout.Logoutfilter.doFilter(Logoutfilter.java:121) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:331) at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(Csrffilter.java:124) at org.springframework.web.filter.Onceperrequestfilter.doFilter(Onceperrequestfilter.java:107) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:331) at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(Headerwriterfilter.java:66) at org.springframework.web.filter.Onceperrequestfilter.doFilter(Onceperrequestfilter.java:107) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:331) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(Webasyncmanagerintegrationfilter.java:56) at org.springframework.web.filter.Onceperrequestfilter.doFilter(Onceperrequestfilter.java:107) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:331) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(Securitycontextpersistencefilter.java:106) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:331) at org.springframework.security.web.Filterchainproxy.doFilterInternal(Filterchainproxy.java:214) at org.springframework.security.web.Filterchainproxy.doFilter(Filterchainproxy.java:177) at org.springframework.web.filter.Delegatingfilterproxy.invokeDelegate(Delegatingfilterproxy.java:346) at org.springframework.web.filter.Delegatingfilterproxy.doFilter(Delegatingfilterproxy.java:262) at io.undertow.Servlet.core.Managedfilter.doFilter(Managedfilter.java:61) at io.undertow.Servlet.handlers.Filterhandler$Filterchainimpl.doFilter(Filterhandler.java:131) at io.undertow.Servlet.handlers.Filterhandler.handleRequest(Filterhandler.java:84) at io.undertow.Servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(Servletsecurityrolehandler.java:62) at io.undertow.Servlet.handlers.Servletdispatchinghandler.handleRequest(Servletdispatchinghandler.java:36) at org.wildfly.Extension.undertow.security.SecurityContextAssociationHandler.handleRequest(Securitycontextassociationhandler.java:78) at io.undertow.server.handlers.Predicatehandler.handleRequest(Predicatehandler.java:43)

pl.java:1161) ... 91 more

the method being used to perform the authentication is this.

@Transactional
    public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException, DataAccessException {

        if (StringUtils.isEmpty(login)) {

            throw new UsernameNotFoundException("Não foi possível localizar o Usuário");
        }

        Optional<Usuario> optional = usuarioService.findByLogin(login);

        if (!optional.isPresent()) {

            LOGGER.error("Não foi possível localizar o login: {}", login);

            throw new UsernameNotFoundException("Não foi possível localizar o Usuário.");
        }

        Usuario usuario = optional.get();

        List<GrantedAuthority> authorities = usuarioService.carregarPerfil(usuario.getPerfil());

        Principal principal = new Principal(usuario.getId(), usuario.getNome(), usuario.getSobrenome(), usuario.getLogin(), usuario.getEmail(),
                usuario.getPerfil().getNome(), usuario.getSenha(), usuario.getSituacao(), authorities);

        LocalDate data = LocalDate.now();
        LocalTime entrada = LocalTime.now();
        LocalTime saidaAlmoco = LocalTime.now();
        LocalTime voltaAlmoco = LocalTime.now();
        LocalTime saida = LocalTime.now();


        List<Folha> findDateUser = folhaService.findByDateAndUser(data, usuario.getId());


        if(findDateUser.size() == 0){

            Folha folha = new  Folha();

            folha.setData(data);
            folha.setUsuario(usuario);
            folhaDAO.persistir(folha);
        } else if(findDateUser.size() != 0){

            Folha folhaEntrada = new Folha();

            long idFolha = 0;

            idFolha = findDateUser.iterator().next().getIdFolha();
            folhaEntrada.setIdFolha(idFolha);
            folhaEntrada.setData(data);
            folhaEntrada.setUsuario(usuario);
            folhaEntrada.setEntrada(entrada);


            folhaDAO.update(folhaEntrada);
        }


        return principal;

    }

}

the problem is the moment I get the id of the sheet entity I hope they can help me.

1 answer

0


Well I managed to solve the problem, the error was in not setting the version I did that and the problem was fixed.

Browser other questions tagged

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