SQLException:ResultSet来自UPDATE。没有数据。春季数据

时间:2017-05-10 13:01:21

标签: java mysql spring spring-data-jpa

我为MySQL编写了一个程序

CREATE DEFINER=`root`@`localhost` PROCEDURE `calculate_user_rank`()
BEGIN

DROP TABLE IF EXISTS `user_rank`;

CREATE TABLE `user_rank`
  AS (SELECT 
user.id, 
(SELECT COUNT(*)+1 FROM user_profile WHERE points>x.points) AS rank FROM 
user_profile x, user WHERE user.user_profile_id = x.id);

UPDATE user, user_rank SET user.rank = user_rank.rank WHERE user.id = user_rank.id;

END

此存储过程根据points表中的user_profile列计算用户排名,制作包含数据的新表user_rank并更新userrank user_rank表中的列。

当我从MySQL Workbench执行此存储过程时,它工作正常。但是当我从JpaRepository称呼它为:

@Transactional
@Query(nativeQuery = true, value = "CALL calculate_user_rank()")
void setUserRank();

它引发了一个例外:

Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.loader.Loader.doList(Loader.java:2620)
at org.hibernate.loader.Loader.doList(Loader.java:2600)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429)
at org.hibernate.loader.Loader.list(Loader.java:2424)
...
Caused by: java.sql.SQLException: ResultSet is from UPDATE. No Data.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6995)

手术有问题吗?

1 个答案:

答案 0 :(得分:0)

仅添加@Modifying。

@Transactional
@Modifying
@Query(nativeQuery = true, value = "CALL calculate_user_rank()")
void setUserRank();