1
votes

I am working on a project with Spring boot. I have a problem with Spring JPA Data. I want to check if a record already exists in the db using two parameters

@Transactional
@Modifying
@Query("SELECT CASE WHEN COUNT(dfe) > 0 THEN 'true' ELSE 'false' END FROM DeployedFunctionEntity dfe WHERE dfe.function.idFunction = ?1 and dfe.gatewayId = ?2")
boolean existsByFunctionIdAndGatewayId(@Param("idFunction") Integer functionId,
        @Param("gatewayId") Integer gatewayId);
boolean exist = deployedFunctionDao.existsByFunctionIdAndGatewayId(functionId, gatewayId);

I always get the following error:

org.springframework.dao.InvalidDataAccessApiUsageException: Modifying queries can only use void or int/Integer as return type!;

The nested exception is

java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type!

How can I fix it?

1

1 Answers

0
votes

The @Modifying has no use for non-modifying queries, thus, must only be used for INSERT, UPDATE, DELETE or DDL queries. Since you are only making a SELECT query, remove the annotation and it'll work without problems.