search(query) throws NullPointerException

你说的曾经没有我的故事 提交于 2019-12-13 04:01:52

问题


    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!


回答1:


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.




回答2:


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




回答3:


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!



来源:https://stackoverflow.com/questions/49923311/searchquery-throws-nullpointerexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!