cancel
Showing results for 
Search instead for 
Did you mean: 

flexible search query return null in java file but working fine in hac

Former Member
0 Kudos

Hi I am trying to fetch some data through a method. My query is working fine in hac but it result null when used in java code. Below is my java code ;-

 public class abc
     {
            @Resource
         private UserService userService;
         @Resource
         private SearchRestrictionService searchRestrictionService;
         @Resource
         private CatalogVersionService catalogVersionService;
     
             public List<ProductModel> findRequiredProducts()
             {
                 this.userService.setCurrentUser(userService.getAdminUser());
                 this.searchRestrictionService.disableSearchRestrictions();
                     this.catalogVersionService.setSessionCatalogVersion("abcCatalog", "Online");
              final String query = "select {p:name},{p.creationtime} from {Product! as p}";
              final FlexibleSearchQuery productQuery = new FlexibleSearchQuery(query);
              final SearchResult<ProductModel> searchResult = getFlexibleSearchService().search(productquery);
              this.searchRestrictionService.enableSearchRestrictions();
             final List<ProductModel> requiredProducts = searchResult.getResult();
     
             }
       
     }
 

Here on executing this code I am getting lazylist[null]" in requiredProduct list. Please suggest the solution.

Former Member
0 Kudos

Seems like that either catalog version is not set correctly or restriction is not disable. So try to debug and see actual query at run time.

Former Member
0 Kudos

@Abishek Dubey I considered your suggestion and checked restriction and catalog version. Found catalog version is fine and there is no restriction as isRestriction method returns false.

Accepted Solutions (1)

Accepted Solutions (1)

andyfletcher
Active Contributor
0 Kudos

You need to select {pk} in your query. The columns {name} and {creationtime} don't help Hybris find your product, they're just data.

e.g.

 String query = "select {p.pk} from {Product! as p}";

Answers (0)