Issue
My current function is like this
public interface CartDAO extends JpaRepository<CartBean, Long>{
@Modifying
@Transactional
@Query(value = "UPDATE cart SET bought =1 WHERE id=?" ,nativeQuery = true)
void buy(Long id);
}
If I want to pass undetermined number of ids to SQL for query, how can I write ?
like this
"UPDATE cart SET bought =1 WHERE id=1 OR id=2 OR id=3 ..."
@Modifying
@Transactional
@Query(value = "UPDATE cart SET bought =1 WHERE id=?..." ,nativeQuery = true)
void buy(Long id...);
Solution
"UPDATE cart SET bought =1 WHERE id=1 OR id=2 OR id=3 ..."
This is what you want.
@Modifying
@Transactional
@Query(value = "UPDATE cart SET bought =1 WHERE id IN :ids" ,nativeQuery = true)
void buy(@Param("ids") List<Long> ids);
Answered By - Panagiotis Bougioukos
Answer Checked By - David Marino (JavaFixing Volunteer)