1

I am using 2 different properties to fetch distinct list eg

findDistinctBy<propertyName>And<propertyName>In(List<String> list).

My actual Spring jpa statement is

List<PojoClass> findAllByTpIdInAndDistinctMobile(List<String> edgeIds);

where TpId & Mobile are 2 different properties in PojoClass. I need to implement this without using Query annotation. Any suggestions of queryDsl will also do.

codeLover
  • 2,571
  • 1
  • 11
  • 27
Tejas 07
  • 79
  • 1
  • 10
  • You can use projection or use Entity Manager to fetch data. You can view bellow thread to check possible solutions: https://stackoverflow.com/a/50365522/3073945 – Md. Sajedul Karim Jul 16 '18 at 12:44
  • The `findBy` methods are designed for simple cases, for more complex logic use `@Query` why jump through hoops if you can write a simple query. – M. Deinum Jul 16 '18 at 13:45

1 Answers1

0

The question needs to be more clear.What exactly do you intend to achieve when the input is a list of Ids?

There is no option to provide a list to findAll unless it is an Id. A simple way would be to loop the the input list in service and append the result to a result list.

for(String edgeId:edgeIds){
    resultList.addAll(findByEdgeId(edgeId));
}

Updated code after @Tejas comment

for(Pojo pojo:Pojos){
   resultList.addAll(findDistinctPojoByPropert1OrPropert2(String pojo.getProperty1(),String pojo.getProperty2());
}
Jibin TJ
  • 416
  • 1
  • 4
  • 15
  • I need to use Distinct & In JPA statement with 2 different pojo property, this need to be implemented without using @Query Annotation – Tejas 07 Jul 17 '18 at 17:40