radu
radu

Reputation: 120

search(query) throws NullPointerException

    public List<DHProductLookupModel> findProductbyCCsapProductId(final String code)
{
    final String queryString = "SELECT {p:" + DHProductLookupModel.SAPPRODUCTID + "}" + "FROM{" + DHProductLookupModel._TYPECODE
            + " AS p}" + "WHERE" + "{p:" + DHProductLookupModel.SAPPRODUCTID + "}=?code ";
    final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString);
    query.addQueryParameter("code", code);
    return flexibleSearchService.<DHProductLookupModel> search(query).getResult();
}

search(query) throws Null Pointer Exception, how to handle this?

Output:

Caused by: java.lang.NullPointerException
    at de.hybris.platform.servicelayer.search.impl.DefaultFlexibleSearchService.getJaloResult(DefaultFlexibleSearchService.java:396) ~[coreserver.jar:?]
    at de.hybris.platform.servicelayer.search.impl.DefaultFlexibleSearchService.search(DefaultFlexibleSearchService.java:168) ~[coreserver.jar:?]
    at com.cancom.core.productlookup.dao.impl.CCProductLookupDaoImpl.findProductbyCCmanufacturerProductId(CCProductLookupDaoImpl.java:39) ~[classes/:?]
    at com.cancom.core.productlookup.service.impl.CCProductLookupServiceImpl.getProductforCCmanufacturerProductId(CCProductLookupServiceImpl.java:37) ~[classes/:?]

Thanks!

Upvotes: 0

Views: 1129

Answers (3)

radu
radu

Reputation: 120

Thanks everyone! I found the Problem. It was in my spring.I just had to put :

 <context:component-scan base-package="myPackage"/>

I changed also the query with DHProductLookupModel.PK for safety. Now it´s work!

Upvotes: 0

HybrisHelp
HybrisHelp

Reputation: 5810

In your case, you can use getModelsByExample of flexibleSearchService instead of writing the query.

Your method will be like

 public List<DHProductLookupModel> findProductbyCCsapProductId(final String code)
 {
     DHProductLookupModel dhProductLookupModel = new DHProductLookupModel();
     dhProductLookupModel.setSapProductID(code);
     return getFlexibleSearchService().getModelsByExample(dhProductLookupModel);
 }

find the example here

Upvotes: 0

Free-Minded
Free-Minded

Reputation: 5430

Change your flexible search query from

 final String queryString = "SELECT {p:" + DHProductLookupModel.SAPPRODUCTID + "}" + "FROM{" + DHProductLookupModel._TYPECODE
        + " AS p}" + "WHERE" + "{p:" + DHProductLookupModel.SAPPRODUCTID + "}=?code ";

to

 final String queryString = "SELECT {p:" + DHProductLookupModel.PK + "}" + "FROM{" + DHProductLookupModel._TYPECODE
        + " AS p}" + "WHERE" + "{p:" + DHProductLookupModel.SAPPRODUCTID + "}=?code ";

You should send DHProductLookupModel.PK in search result.

Upvotes: 2

Related Questions