使用 FlexibleSearchService Hybris 在数据库 table 中搜索

Search in database table using FlexibleSearchService Hybris

我尝试制作一个需要在数据库中搜索项目的 DAO table。我是 Hybris 的新手,所以我不知道这里到底出了什么问题(查询或我的垃圾代码)。那就是cmd中出现的错误。

SEVERE: Servlet.service() for servlet [DispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is de.hybris.platform.servicelayer.search.exceptions.FlexibleSearchException: SQL search error - enable the property 'flexible.search.exception.show.query.details' for more details] with root cause java.sql.SQLException: Invalid value for getLong()

那是我的 DAO class 实现

@Component(value = "arbRedirectHttpTypeDao")
public class ArbRedirectHttpTypeDaoImpl implements ArbRedirectHttpTypeDao {

private static final Logger LOG = Logger.getLogger(ArbRedirectHttpTypeDaoImpl.class);

@Autowired
private FlexibleSearchService flexibleSearchService;

public FlexibleSearchService getFlexibleSearchService() {
    return flexibleSearchService;
}

public void setFlexibleSearchService(FlexibleSearchService flexibleSearchService) {
    this.flexibleSearchService = flexibleSearchService;
}

@Override
public ArbRedirectHttpTypeModel findNewUrlByOldUrl(String oldUrl) {

    final String query = "SELECT {"+ ArbRedirectHttpTypeModel.NEWURL +"}"
            + " FROM {"+ ArbRedirectHttpTypeModel._TYPECODE +"} WHERE {"
            + ArbRedirectHttpTypeModel.OLDURL +"}=?oldUrl";

    final FlexibleSearchQuery flexibleSearchQuery = new FlexibleSearchQuery(query);

    flexibleSearchQuery.addQueryParameter("oldUrl", oldUrl);

    final List<ArbRedirectHttpTypeModel> locationsByCode = flexibleSearchService
            .<ArbRedirectHttpTypeModel> search(flexibleSearchQuery)
            .getResult();

    LOG.info("-------------------------------------" + locationsByCode.get(0));
    if (locationsByCode != null && !locationsByCode.isEmpty())
    {
        return locationsByCode.get(0);
    }
    else
    {
        return null;
    }

}
}

这里我试着称呼它

 @Resource
 private ArbRedirectHttpTypeDao arbRedirectHttpTypeDao;
ArbRedirectHttpTypeModel arbRedirectHttpTypeModel = arbRedirectHttpTypeDao.findNewUrlByOldUrl("/Aapuvdc");
"SELECT {"+ ArbRedirectHttpTypeModel.NEWURL +"}"

在这里您尝试 return 模型的 NEWURL,我假设它是一个字符串。灵活的搜索查询 returns 来自项目的 pk,默认情况下将其转换为 hybris 模型。而是尝试将您的查询重新组织为 select pk

"SELECT {"+ ArbRedirectHttpTypeModel.PK +"}"

或者您可以保持查询不变,并将查询的 return 类型设置为 FlexibleSearchQuery.setResultClassList(classList);,例如:

flexibleSearchQuery.setResultClassList(Collections.singletonList(String.class));

您也不必将 .search() 转换为 ArbRedirectHttpTypeModel。你可以选择

SearchResult<String> result = flexibleSearchService.search(flexibleSearchQuery).getResult();
return result.getCount() > 0 ? result.getResult().get(0) : null;

使用“SELECT {“+ ArbRedirectHttpTypeModel.PK +“}”。它将 return 对象,您可以通过 getter

获取所有属性