I have written a query to delete some objects in my interface extending JPaRepository, but when I execute the query it throws an exception!
Can anyone explain
Try this:
public interface LimitRepository extends JpaRepository {
@Transactional
@Modifying
@Query("delete from CLimit l where l.trader.id =:#{#trader.id}")
void deleteLimitsByTrader(@Param("trader") CTrader trader);
}
Whenever you are trying to modify a record in db, you have to mark it @Transactional as well as @Modifying, which instruct Spring that it can modify existing records.
The repository method must be void or the exception keeps getting thrown.