Solucao aceita
Lucas_Camara 2 de ago. de 2021 1 like
Todo link irá realizar uma requisição GET pedindo algo ao servidor. Isso é padrão.
Se vc quiser realizar uma requisição POST vc deve declarar um formulário informando o verbo a ser utilizado. Algo mais ou menos assim:
<td>
<form method= "post" action= "/excluir?id=<c:out value="${listaClientes.id}" > ">
<button type= "submit" > Excluir Cliente</button>
</form>
</td>
Como é para remover algo do servidor, vc pode dá uma olhada no verbo DELETE para isso.
Carlos_Henrique5 2 de ago. de 2021
Fiz suas alterações e obtive sucesso no excluir. Resolvi fazer o mesmo para o alterar e estou recebendo esse erro:
Required request parameter ' id ' for method parameter type long is not present
org . springframework . web . bind . MissingServletRequestParameterException : Required request parameter ' id ' for method parameter type long is not present
Alterações que fiz:
<td><form method= "get" action= "/listarClientesID?id=<c:out value="${listaClientes.id}" ></c:out> ">
<button type= "submit" > Alterar </button>
</form>
</td>
<td><form method= "post" action= "/excluirCliente?id=<c:out value="${listaClientes.id}" ></c:out> ">
<button type= "submit" > Excluir </button>
</form>
</td>
Lucas_Camara 3 de ago. de 2021
A ação de alterar deveria ser a /listarClientesID mesmo?
E pelo erro, é bem capaz que o método esteja esperando um parâmetro id que não foi informado. Como está implementada a ação de alterar?
Carlos_Henrique5 3 de ago. de 2021
Ele só ocorre este problema quando utilizo um button. Antes eu estava utilizando um link e ele funcionava normalmente chamando o formulário para alteração.
@GetMapping ( value = "/listarClientesID" )
public ModelAndView listarCliente ( @RequestParam ( "id" ) long id ) {
ModelAndView modelo = new ModelAndView ( "AlterarCliente" );
Optional < Cliente > clienteID = repositorio . findById ( id );
modelo . addObject ( "clientes" , clienteID . get ());
return modelo ;
}
formulário para alteração
<% @ page language = "java" contentType = "text/html; charset=ISO-8859-1"
pageEncoding = "ISO-8859-1" %>
<% @ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<!DOCTYPE html>
< html >
< head >
< meta charset = "ISO-8859-1" >
< title > Insert title here</ title >
</ head >
< body >
< h1 > Alterar Cliente</ h1 >
< form action = "/salvarClienteAlterado" method = "post" >
ID: < input type = "number" required = "required" name = "id" value = '<c:out value="${clientes.id}"></c:out>' >
< br ></ br >
Nome: < input type = "text" required = "required" name = "nome" value = '<c:out value="${clientes.nome }"></c:out>' >
< br ></ br >
CPF: < input type = "cpf" required = "required" name = "cpf" value = '<c:out value="${clientes.cpf }"></c:out>' >
< br ></ br >
Rua: < input type = "text" required = "required" name = "rua" value = '<c:out value="${clientes.endereco.rua }"></c:out>' >
< br ></ br >
Bairro: < input type = "text" required = "required" name = "bairro" value = '<c:out value="${clientes.endereco.bairro}"></c:out>' >
< br ></ br >
Número: < input type = "number" required = "required" name = "numero" value = '<c:out value="${clientes.endereco.numero}"></c:out>' >
< br ></ br >
CEP: < input type = "text" required = "required" name = "cep" value = '<c:out value="${clientes.endereco.cep}"></c:out>' >
< br ></ br >
< input type = "submit" value = "Salvar" >
</ form >
</ body >
</ html >
Lucas_Camara 3 de ago. de 2021 1 like
Vc não precisa de um form para realizar um GET . O link (todo link realiza um GET no servidor) é a forma correta de fazer msm (eu achei que o alterar fosse a alteração de fato, e não a chamada para a tela de alteração).
Carlos_Henrique5 3 de ago. de 2021 1 like
Entendi. Eu até já tinha deixado com o link mesmo. Eu só estava querendo entender pq através de um formulário ele não conseguia executar a ação. Obrigado pela ajuda e atenção! Outra coisa se não for incomodo, vc poderia explicar pq ele não executa a ação quando está dentro de um formulário ? (só por curiosidade mesmo).
Lucas_Camara 3 de ago. de 2021 1 like
O GET dentro do form, provavelmente não funcionou pq, dentro do form os query params deveriam, acredito, ser declarados na forma de input:
<form method= "get" action= "/listarClientesID" >
<input type= "hidden" id= "id" name= "id" value= "<c:out value="${listaClientes.id}" ></c:out> ">
<button type= "submit" > Alterar </button>
</form>
Carlos_Henrique5 3 de ago. de 2021 1 like
Realmente funcionou e entendi sua explicação! Muito obrigado pela ajuda. Foi de extrema importância em meu aprendizado.
Alex_Gaeta 16 de jan. de 2022
pessoal, tentei seguir o processo acima e o meu alterar continua dando erro, sou novo na programação estou tentando aprender na raça rs
aqui estao os meu cod.
Meu form
<div class= "container left" >
<h3 class= "light-green-text text-darken-1" > Alteração de Usuários</h3>
<form th:action= "@{/altUsuarios}" method= "post"
> <!-- onsubmit="return confirm('Confirma ação?')" -->
<div class= "row" >
<div class= "input-field col s5" >
Nome:<input type= "text" th:value= ${usuario.nome} required= "required" value= "" name= "nome" >
</div>
<div class= "input-field col s5" >
Senha:<input type= "password" th:value= ${usuario.senha} required= "required" value= "" name= "senha" >
</div>
</div>
<div class= "row" >
<div class= "input-field col s8" >
Nivel de Acesso: <select name= "nivelacesso" th:value= ${usuario.nivelacesso} required= "required"
class= "browser-default" >
<option value= "" disabled selected > Escolha uma Opção</option>
<option value= "RULE_ADMIN" > Administrador</option>
<option value= "RULE_USER" > Usuário</option>
</select>
</div>
</div>
<button class= "btn waves-effect light-green darken-1" type= "submit"
name= "action" >
Salvar <i class= "material-icons right" > send</i>
</button>
<button class= "btn waves-effect light-green darken-1" type= "reset"
name= "action" >
Limpar <i class= "material-icons right" > send</i>
</button>
</form>
meu metodo
@RequestMapping ( "usuarios/altUsuarios/{id}" )
public String altUsuarios ( @PathVariable ( "id" ) Integer id , Model model ) {
System . out . println ( id );
Usuarios usuario = re . findByIdusuario ( id );
model . addAttribute ( "usuario" , usuario );
return "usuarios/formUsuarios" ;
}
@RequestMapping ( "/altUsuarios" )
public ModelAndView atualiza ( Usuarios usuarios ) {
re . save ( usuarios );
//return "redirect:/cadUsuarios";
return new ModelAndView ( "redirect:/cadUsuarios" );
}
Este é o erro de duplicidade na chave
org . postgresql . util . PSQLException : ERROR : duplicate key value violates unique constraint "uk_exw5vja1pgfobcpqtldhnx6uv"
Detalhe : Key ( nome ) = ( Joao ) already exists .
at org . postgresql . core . v3 . QueryExecutorImpl . receiveErrorResponse ( QueryExecutorImpl . java : 2674 ) ~ [ postgresql - 42.3 . 1.j ar : 42.3 . 1 ]
at org . postgresql . core . v3 . QueryExecutorImpl . processResults ( QueryExecutorImpl . java : 2364 ) ~ [ postgresql - 42.3 . 1.j ar : 42.3 . 1 ]
at org . postgresql . core . v3 . QueryExecutorImpl . execute ( QueryExecutorImpl . java : 354 ) ~ [ postgresql - 42.3 . 1.j ar : 42.3 . 1 ]
at org . postgresql . jdbc . PgStatement . executeInternal ( PgStatement . java : 484 ) ~ [ postgresql - 42.3 . 1.j ar : 42.3 . 1 ]
at org . postgresql . jdbc . PgStatement . execute ( PgStatement . java : 404 ) ~ [ postgresql - 42.3 . 1.j ar : 42.3 . 1 ]
at org . postgresql . jdbc . PgPreparedStatement . executeWithFlags ( PgPreparedStatement . java : 162 ) ~ [ postgresql - 42.3 . 1.j ar : 42.3 . 1 ]
at org . postgresql . jdbc . PgPreparedStatement . executeUpdate ( PgPreparedStatement . java : 130 ) ~ [ postgresql - 42.3 . 1.j ar : 42.3 . 1 ]
at org . hibernate . engine . jdbc . internal . ResultSetReturnImpl . executeUpdate ( ResultSetReturnImpl . java : 197 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . engine . jdbc . batch . internal . NonBatchingBatch . addToBatch ( NonBatchingBatch . java : 46 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . persister . entity . AbstractEntityPersister . insert ( AbstractEntityPersister . java : 3375 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . persister . entity . AbstractEntityPersister . insert ( AbstractEntityPersister . java : 3908 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . action . internal . EntityInsertAction . execute ( EntityInsertAction . java : 107 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . engine . spi . ActionQueue . executeActions ( ActionQueue . java : 604 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . engine . spi . ActionQueue . lambda $ executeActions $ 1 ( ActionQueue . java : 478 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at java . base / java . util . LinkedHashMap . forEach ( LinkedHashMap . java : 721 ) ~ [ na : na ]
at org . hibernate . engine . spi . ActionQueue . executeActions ( ActionQueue . java : 475 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . event . internal . AbstractFlushingEventListener . performExecutions ( AbstractFlushingEventListener . java : 344 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . event . internal . DefaultFlushEventListener . onFlush ( DefaultFlushEventListener . java : 40 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . event . service . internal . EventListenerGroupImpl . fireEventOnEachListener ( EventListenerGroupImpl . java : 107 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . internal . SessionImpl . doFlush ( SessionImpl . java : 1402 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . internal . SessionImpl . managedFlush ( SessionImpl . java : 493 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . internal . SessionImpl . flushBeforeTransactionCompletion ( SessionImpl . java : 3285 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . internal . SessionImpl . beforeTransactionCompletion ( SessionImpl . java : 2420 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . engine . jdbc . internal . JdbcCoordinatorImpl . beforeTransactionCompletion ( JdbcCoordinatorImpl . java : 449 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . resource . transaction . backend . jdbc . internal . JdbcResourceLocalTransactionCoordinatorImpl . beforeCompletionCallback ( JdbcResourceLocalTransactionCoordinatorImpl . java : 183 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . resource . transaction . backend . jdbc . internal . JdbcResourceLocalTransactionCoordinatorImpl . access $ 300 ( JdbcResourceLocalTransactionCoordinatorImpl . java : 40 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . resource . transaction . backend . jdbc . internal . JdbcResourceLocalTransactionCoordinatorImpl $ TransactionDriverControlImpl . commit ( JdbcResourceLocalTransactionCoordinatorImpl . java : 281 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . hibernate . engine . transaction . internal . TransactionImpl . commit ( TransactionImpl . java : 101 ) ~ [ hibernate - core - 5.6 . 3. Final . jar : 5.6 . 3. Final ]
at org . springframework . orm . jpa . JpaTransactionManager . doCommit ( JpaTransactionManager . java : 562 ) ~ [ spring - orm - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . transaction . support . AbstractPlatformTransactionManager . processCommit ( AbstractPlatformTransactionManager . java : 743 ) ~ [ spring - tx - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . transaction . support . AbstractPlatformTransactionManager . commit ( AbstractPlatformTransactionManager . java : 711 ) ~ [ spring - tx - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . transaction . interceptor . TransactionAspectSupport . commitTransactionAfterReturning ( TransactionAspectSupport . java : 654 ) ~ [ spring - tx - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . transaction . interceptor . TransactionAspectSupport . invokeWithinTransaction ( TransactionAspectSupport . java : 407 ) ~ [ spring - tx - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . transaction . interceptor . TransactionInterceptor . invoke ( TransactionInterceptor . java : 119 ) ~ [ spring - tx - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 186 ) ~ [ spring - aop - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . dao . support . PersistenceExceptionTranslationInterceptor . invoke ( PersistenceExceptionTranslationInterceptor . java : 137 ) ~ [ spring - tx - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 186 ) ~ [ spring - aop - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . data . jpa . repository . support . CrudMethodMetadataPostProcessor $ CrudMethodMetadataPopulatingMethodInterceptor . invoke ( CrudMethodMetadataPostProcessor . java : 174 ) ~ [ spring - data - jpa - 2.6 . 0.j ar : 2.6 . 0 ]
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 186 ) ~ [ spring - aop - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . aop . interceptor . ExposeInvocationInterceptor . invoke ( ExposeInvocationInterceptor . java : 97 ) ~ [ spring - aop - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 186 ) ~ [ spring - aop - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . aop . framework . JdkDynamicAopProxy . invoke ( JdkDynamicAopProxy . java : 215 ) ~ [ spring - aop - 5.3 . 14.j ar : 5.3 . 14 ]
at jdk . proxy29 / jdk . proxy29 .$ Proxy300 . save ( Unknown Source ) ~ [ na : na ]
at com . example . consultorio . controller . ConUsuarios . Salvar ( ConUsuarios . java : 46 ) ~ [ classes / : na ]
at java . base / jdk . internal . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method ) ~ [ na : na ]
at java . base / jdk . internal . reflect . NativeMethodAccessorImpl . invoke ( NativeMethodAccessorImpl . java : 77 ) ~ [ na : na ]
at java . base / jdk . internal . reflect . DelegatingMethodAccessorImpl . invoke ( DelegatingMethodAccessorImpl . java : 43 ) ~ [ na : na ]
at java . base / java . lang . reflect . Method . invoke ( Method . java : 568 ) ~ [ na : na ]
at org . springframework . web . method . support . InvocableHandlerMethod . doInvoke ( InvocableHandlerMethod . java : 205 ) ~ [ spring - web - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . method . support . InvocableHandlerMethod . invokeForRequest ( InvocableHandlerMethod . java : 150 ) ~ [ spring - web - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . servlet . mvc . method . annotation . ServletInvocableHandlerMethod . invokeAndHandle ( ServletInvocableHandlerMethod . java : 117 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . servlet . mvc . method . annotation . RequestMappingHandlerAdapter . invokeHandlerMethod ( RequestMappingHandlerAdapter . java : 895 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . servlet . mvc . method . annotation . RequestMappingHandlerAdapter . handleInternal ( RequestMappingHandlerAdapter . java : 808 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . servlet . mvc . method . AbstractHandlerMethodAdapter . handle ( AbstractHandlerMethodAdapter . java : 87 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . servlet . DispatcherServlet . doDispatch ( DispatcherServlet . java : 1067 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . servlet . DispatcherServlet . doService ( DispatcherServlet . java : 963 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . servlet . FrameworkServlet . processRequest ( FrameworkServlet . java : 1006 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . servlet . FrameworkServlet . doPost ( FrameworkServlet . java : 909 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 681 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 4.0 . FR ]
at org . springframework . web . servlet . FrameworkServlet . service ( FrameworkServlet . java : 883 ) ~ [ spring - webmvc - 5.3 . 14.j ar : 5.3 . 14 ]
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 764 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 4.0 . FR ]
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 227 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 162 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . tomcat . websocket . server . WsFilter . doFilter ( WsFilter . java : 53 ) ~ [ tomcat - embed - websocket - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 189 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 162 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . springframework . web . filter . RequestContextFilter . doFilterInternal ( RequestContextFilter . java : 100 ) ~ [ spring - web - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . filter . OncePerRequestFilter . doFilter ( OncePerRequestFilter . java : 117 ) ~ [ spring - web - 5.3 . 14.j ar : 5.3 . 14 ]
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 189 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 162 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . springframework . web . filter . FormContentFilter . doFilterInternal ( FormContentFilter . java : 93 ) ~ [ spring - web - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . filter . OncePerRequestFilter . doFilter ( OncePerRequestFilter . java : 117 ) ~ [ spring - web - 5.3 . 14.j ar : 5.3 . 14 ]
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 189 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 162 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . springframework . web . filter . CharacterEncodingFilter . doFilterInternal ( CharacterEncodingFilter . java : 201 ) ~ [ spring - web - 5.3 . 14.j ar : 5.3 . 14 ]
at org . springframework . web . filter . OncePerRequestFilter . doFilter ( OncePerRequestFilter . java : 117 ) ~ [ spring - web - 5.3 . 14.j ar : 5.3 . 14 ]
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 189 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 162 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 197 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 97 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . authenticator . AuthenticatorBase . invoke ( AuthenticatorBase . java : 540 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 135 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 92 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 78 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 357 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . coyote . http11 . Http11Processor . service ( Http11Processor . java : 382 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . coyote . AbstractProcessorLight . process ( AbstractProcessorLight . java : 65 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . coyote . AbstractProtocol $ ConnectionHandler . process ( AbstractProtocol . java : 895 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . tomcat . util . net . NioEndpoint $ SocketProcessor . doRun ( NioEndpoint . java : 1732 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . tomcat . util . net . SocketProcessorBase . run ( SocketProcessorBase . java : 49 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . tomcat . util . threads . ThreadPoolExecutor . runWorker ( ThreadPoolExecutor . java : 1191 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . tomcat . util . threads . ThreadPoolExecutor $ Worker . run ( ThreadPoolExecutor . java : 659 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at org . apache . tomcat . util . threads . TaskThread $ WrappingRunnable . run ( TaskThread . java : 61 ) ~ [ tomcat - embed - core - 9.0 . 56.j ar : 9.0 . 56 ]
at java . base / java . lang . Thread . run ( Thread . java : 833 ) ~ [ na : na ]
Lucas_Camara 16 de jan. de 2022
Provavelmente seu código está tentando inserir um outro usuário com um nome que já está cadastrado, e vc tem uma constraint para impedir mais de um usuário com o mesmo nome. Por isso ocorreu o erro.
Ao realizar o save, o ID da entidade está preenchida?