gpt4 book ai didi

spring - Spring Data JPA中@Modifying方法的返回值是什么意思

转载 作者:行者123 更新时间:2023-12-04 02:50:19 24 4
gpt4 key购买 nike

@Repository
public interface LoginDao extends JpaRepository<LoginEntity, Integer> { //}, LoginDaoCustom {
LoginEntity findByLogin(String login);

@Modifying
int changePassword(String password, String login);
}

如果我将 changePassword 的返回值更改为 int 以外的任何值,我会收到以下错误。
Caused by: java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type!
at org.springframework.util.Assert.isTrue(Assert.java:65)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.<init>(JpaQueryExecution.java:166)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.getExecution(AbstractJpaQuery.java:106)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:86)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
... 46 more

这个整数返回值是什么意思?我确信 Spring 在某处记录了它,但我找不到它。它未在 jpa.modifying-queries 中列出

我应该补充一点,如果确实将返回类型声明为 int,则更新会静默失败并且值不会更新。

最佳答案

int/Integer 返回值是数据库中更新的行数。

关于spring - Spring Data JPA中@Modifying方法的返回值是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22818598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com