我知道jpa存储库提供save()方法来持久化对象。但是我想自己做,我试图在表中插入一些东西,但是有一个错误 "could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement"
出现在 Postman 回复中。这是我的密码
我的存储库
@Modifying
@Query(value = "insert into TipoAcesso (accesTypeId,accessTypeName,subAcessTypeName,user_id) VALUES (:accesTypeId,Quarto,null,:user_id)",nativeQuery = true)
@Transactional
void insertAccesTypeQuartosToUser(@Param("user_id") Long userId);
我的控制器
@PostMapping(value = "/acessoCozinha")
public ResponseEntity<Response<TipoAcesso>> insertAccessCozinha(HttpServletRequest request) {
TipoAcesso tipoAcesso = new TipoAcesso();
Response<TipoAcesso> response = new Response<>();
try {
tipoAcesso.setUser(userFromRequest(request));
tiposAcessoService.insertAccesTypeCozinhaToUser(tipoAcesso);
} catch (Exception e) {
response.getErrors().add(e.getMessage());
return ResponseEntity.badRequest().body(response);
}
return ResponseEntity.ok(response);
}
暂无答案!
目前还没有任何答案,快来回答吧!