0

I have a parameter of integers. I need to write a custom Spring JPA query where the equivalent SQL would be . . . AND x.propertyStatusId IN (1,2) . . .

I see in the Spring Data JPA documentation the keyword is "IN" as in "findByAgeIn(Collection<Age> ages)" that translates to "where x.age in ?1" But I get an error. I am using an arrayList of integers.

ArrayList<Integer> propertyStatusId = new ArrayList<Integer>();
propertyStatusId.add(1);
propertyStatusId.add(2);
findByPropertyOwnerIdAndIn(propertyStatusId)AndListingDateGreaterThanEqual(user.getId(),propertyStatusId, ListingDate, pageable);
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
STP
  • 51
  • 8
  • 4
    Possible duplicate of [Spring CrudRepository findByInventoryIds(List inventoryIdList) - equivalent to IN clause](https://stackoverflow.com/questions/18987292/spring-crudrepository-findbyinventoryidslistlong-inventoryidlist-equivalen) – Scrobot May 08 '19 at 04:22

1 Answers1

1

Assuming that you have an entity called Product defined as below:

@Entity
public class Product {

    @Id
    @GeneratedValue
    private Integer id;
    private String title;
    private String description;
    private Date createDate;

// getters & setters 

}

If you would need to query based on title, List of ids and greater than or equal to createDate then you can define the method like below:

List<Product> findByTitleAndIdInAndCreateDateGreaterThanEqual(String title, List<Integer> ids, Date createDate);
snmaddula
  • 1,111
  • 1
  • 7
  • 21
  • yes this compiled and helped me get past the compilation errors around the construction of this specific part. I am still having an issue with the error about it doesn't recognize the property name for some reason. But I will resolve that as I have had that before ( I am aware it is the entity name not the SQL name etc). Thanks – STP May 08 '19 at 17:16
  • I'm glad to hear this. Thank you @STP! – snmaddula May 08 '19 at 17:52