简体   繁体   English

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

[英]Search in database table using FlexibleSearchService Hybris

I try to make a DAO what needs to search for an item in the database table.我尝试制作一个需要在数据库表中搜索项目的 DAO。 I'm pretty new in Hybris so I don't know what is wrong exactly here (query or my junk code).我是 Hybris 的新手,所以我不知道这里到底出了什么问题(查询或我的垃圾代码)。 That is the error that appears in cmd.那是出现在cmd中的错误。

SEVERE: Servlet.service() for servlet [DispatcherServlet] in context with path [] threw exception [Request processing failed;严重:servlet [DispatcherServlet] 的 Servlet.service() 在路径 [] 的上下文中引发异常 [请求处理失败; 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()嵌套异常是 de.hybris.platform.servicelayer.search.exceptions.FlexibleSearchException: SQL 搜索错误 - 启用属性 'flexible.search.exception.show.query.details' 以获取更多详细信息] 其根本原因是 java.sql.SQLException: getLong() 的值无效

That is my DAO class implementation那是我的 DAO 类实现

@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;
    }

}
}

And here I try to call it在这里我试着称之为

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

In here you're trying to return the NEWURL of the model, which I assume will be a string.在这里,您试图返回模型的NEWURL ,我假设它将是一个字符串。 Flexible search query returns the pk from the item and casts it to hybris model by default.灵活的搜索查询从项目中返回 pk 并默认将其转换为 hybris 模型。 Instead try to reorganize your query to select the pk而是尝试重新组织您的查询以选择 pk

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

Or you can leave the query as it is and set the return type of the query with FlexibleSearchQuery.setResultClassList(classList);或者您可以保持查询FlexibleSearchQuery.setResultClassList(classList); ,并使用FlexibleSearchQuery.setResultClassList(classList);设置查询的返回类型FlexibleSearchQuery.setResultClassList(classList); such as:如:

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

You don't have to cast .search() to ArbRedirectHttpTypeModel either.您也不ArbRedirectHttpTypeModel .search()ArbRedirectHttpTypeModel You can just go with你可以去

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

use "SELECT {"+ ArbRedirectHttpTypeModel.PK +"}".使用“SELECT {”+ ArbRedirectHttpTypeModel.PK +“}”。 It will return object and you can get all attribute by getter它将返回对象,您可以通过 getter 获取所有属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM