Issue
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.
Solution
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);
Answered By - Mr.J4mes
Answer Checked By - Cary Denson (JavaFixing Admin)