1

I am using spring-data-jpa, I want update something, I have annotated my method in PaySupplierSettleBillRepository as

public interface PaySupplierSettleBillRepository extends JpaRepository<PaySupplierSettleBillEntity, Long>,
        JpaSpecificationExecutor<PaySupplierSettleBillEntity> {

    @Modifying
    @Query("update PaySupplierSettleBillEntity p set p.payTime=:payTime,p.paymentOrder=:paymentOrder, p.transferTime=:transferTime, p.transferBank=:transferBank, p.transferOrder=:transferOrder, p.operatorName=:operatorName, p.remark=:remark where p.orderNumber=:orderNumber")
    int updatePayInfo(PaySupplierSettleBillEntity entity);
}

I am getting following exception while starting

Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract xxxxxx

how I fix it ? thinks.

1
  • I don't want use ` Custom Implementations for Spring Data Repositories` way Commented May 9, 2019 at 6:10

2 Answers 2

5

That is not how you write a @Query with named parameters. Take a look at the example from Spring documentation here (https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.named-parameters).

If you want to provide an object as param, you can do something like this.

@Query("UPDATE Entity E SET E.name = :#{#entity.name}")
public void updateEntity(@Param("entity") Entity entity);
Sign up to request clarification or add additional context in comments.

1 Comment

This is awesome
3

Caused by: java.lang.IllegalStateException: Using named parameters for method can be thrown when a method has redundant parameter which is not used in the @Query.

In your case, entity should be used in the SQL query like it's mentioned in the previous answer https://stackoverflow.com/a/56053250/5962766 or you should replace it with specifying necessary parameters one by one in the method signature.

Related: IllegalStateException with naming parameters in tomcat

1 Comment

<3. In my case one of the parameter was not used in the query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.