Showing posts with the label getModelByExample

get models by example in Hybris

Sometimes, we are required to fetch data from our custom Item type in Hybris. So first thing comes to our mind is to write flexible search query. But you really don't need to do that if you know Hybris OOTB has  getModelByExample  and  getModelsByExample  API of  flexibleSearchService , using which we can easily get the desired results. Scenario Find CustomProduct having the same name Solution You can create a method in DAO class. In which you need to create example model by setting required field (e.g name). Now call getModelsByExample method of the flexibleSearchService with exampleModel. public List < CustomProductModel > findProductHavingSameName ( final String name ) { CustomProductModel exampleModel = new CustomProductModel (); exampleModel . setName ( name ); return getFlexibleSearchService (). getModelsByExample ( exampleModel ); }