无法提取ResultSet;嵌套的异常是org.hibernate.exception.GenericJDBCException:无法提取ResultSet

时间:2019-06-12 10:45:08

标签: rest spring-boot sql-delete

我想插入一些数据,在插入之前我想删除以前的数据。但是,出现“无法提取ResultSet;嵌套的异常是org.hibernate.exception.GenericJDBCException:无法提取ResultSet”此错误。 / p>

我的控制器类

@PostMapping(path="signin",produces = "application/json")
@ResponseBody public LoginView loginProcess( @RequestBody User user){

try {
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    Date newdate = new Date(date.getTime()+9*3600*1000);

this.loginRepository.delete(user.getUsername());
this.loginRepository.insert(user.getUsername(),user.getDetails(),dateFormat.format(date),dateFormat.format(newdate));

catch(Exception e) {
        System.out.println(e.getMessage());
    }
}

存储库类

public interface LoginRepository extends JpaRepository<User, Integer>{


@Query(value="INSERT INTO DBA.TOKEN_DETAILS (username,TOKEN,ACTIVE,VALID_FROM,VALID_TO) VALUES(:username,:token,1,:validFrom,:validTo)",nativeQuery=true)
public void insertToken(@Param("username")String username, @Param("token")String token, @Param("validFrom")String validFrom, @Param("validTo")String validTo);

@Transactional
@Modifying 
@Query(value="DELETE FROM DBA.TOKEN_DETAILS WHERE username=?1",nativeQuery=true)
public void deleteToken(String username);

}

我得到的错误日志是-

2019-06-12 15:52:10.654  WARN 11120 --- [nio-8087-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: JZ0R2
2019-06-12 15:52:10.654 ERROR 11120 --- [nio-8087-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : JZ0R2: No result set for this query.
could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet

1 个答案:

答案 0 :(得分:0)

已通过在存储库类中添加@Modifying注释解决了该问题

@Modifying
    @Query(value="INSERT INTO DBA.TOKEN_DETAILS (username,TOKEN,ACTIVE,VALID_FROM,VALID_TO) VALUES(:username,:token,1,:validFrom,:validTo)",nativeQuery=true)
    public void insertToken(@Param("username")String username, @Param("token")String token, @Param("validFrom")String validFrom, @Param("validTo")String validTo);