Я хотел бы прочитать все записи из базы данных с предоставленным массивом значений вложенных свойств в Java Spring. У меня есть 2 объекта базы данных:
@Entity
public class Category {
@Id
GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
// other properties, getters and setters
}
@Entity
public class Item {
@ManyToOne
private Category category;
// id, other properties, getters and setters...
}
Теперь я хотел бы прочитать все записи Item
, чьи Category
имеют идентификатор из массива { 4, 12, 15 }
. Есть ли способ сделать это с помощью JpaRepository
?
public interface ItemRepository extends JpaRepository<Item, Integer> {
// Something like that.
List<Item> findAllByCategoryIdIn(List<Integer> categoryIds);
}