Use clause "WHERE IN ()" IN SPRING BOOT JPA?

1

Does anyone know how I can use some clause similar to WHERE IN in spring jpa ?

example:

@Modifying
@Transactional
@Query(value = "Delete from table where id in(:ids)",nativeQuery=true)
    void deleteByIdid(@Param("ids") String var);

I've tried to send a String like this:

5151,5151,51515,884,8484.

But it does not work.

Message

couldn't execute statement.

I believe that when passing the parameter the spring places the variável in quotes.

    
asked by anonymous 18.03.2016 / 18:28

1 answer

3

You can use spring data and do dynamic queries link

Example:

findByInventoryIdIn(List<Long> inventoryIdList)

You can find more information in the Spring Data documentation - link

If you prefer to continue using query methods, I believe you will need to change the parameter to a list, eg

@Query("SELECT t FROM Table t WHERE t.id IN :ids")
Set<Table> findByTableIn(Set<Long> ids);

However, I understand that the first option is preferable:)

You can adapt this option for your DELETE

    
18.03.2016 / 18:44