Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does the return value of @Modifying methods in Spring Data JPA mean

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

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

If I change the return value of the changePassword to anything other than int, I get the error below.

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

What does this integer return value mean ? I am sure spring has it documented somewhere, but I can't find it. It is not listed in the jpa.modifying-queries

I should add that if do declare the return type as int, the update fails silently and values aren't updated.

like image 624
ShaggyInjun Avatar asked Apr 02 '14 17:04

ShaggyInjun


Video Answer


1 Answers

The int/Integer return value is the number of rows that where updated in the database.

like image 55
geoand Avatar answered Oct 13 '22 20:10

geoand