1
public interface InventoryRepository extends JPARepository<Inventory, Long> {

List<Inventory> findByIdIn(List<Long> ids);

}

Above is working fine, however in same way I am trying to fetch the List or Map, based on multiple params List ids and List sortNumber.

I would be also happy with return type Map from the method.

I came up with below things, which isn't correct.

List<Inventory> findByIdANDSortNumberIn(List<Long> ids, List<Long> sortNumbers);

Should do it with help of Criteria ? Is there any better way to do it?

Entity :

@Entity
@Table(name = Constants.T_INVENTROTY)
@Data
public class Inventory implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@Column(name = Constants.COLUMN_IN_DM)
private Long id;

@Column(name = Constants.COLUMN_PROD_DESCRIPTION)
private String prodDescription;


@Column(name = Constants.COLUMN_PROD_DESCRIPTION)
private Long sortNumber;

@Column(name = Constants.COLUMN_QUANTITY)
private long quantity

}
S-Man
  • 22,521
  • 7
  • 40
  • 63
freaksterz
  • 83
  • 3
  • 9

1 Answers1

3

This should work

List<Inventory> findByIdInAndSortNumberIn(List<Long> ids, List<Long> sortNumbers);

You can specify And and do the same for multiple fields.

pvpkiran
  • 25,582
  • 8
  • 87
  • 134