我试图创建一个DAO,它需要在数据库表中搜索项目。我是Hybris的新手,所以我不知道这里到底出了什么问题(查询或我的垃圾代码(。这就是cmd中出现的错误。
SEVERE:路径为[]的上下文中Servlet[DispatcherServlet]的Servlet.service((引发异常[请求处理失败;嵌套异常为de.hybris.platform.servicelayer.search.exceptions.FlexibleSearchException:SQL搜索错误-启用属性"flexible.search.eexception.show.query.details"以获取更多详细信息]java.sql.SQLException:getLong((的值无效
这是我的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;
}
}
}
在这里我试着称之为
@Resource
private ArbRedirectHttpTypeDao arbRedirectHttpTypeDao;
ArbRedirectHttpTypeModel arbRedirectHttpTypeModel = arbRedirectHttpTypeDao.findNewUrlByOldUrl("/Aapuvdc");
使用"SELECT{〃+ArbRedirectHttpTypeModel.PK+〃}〃;。它将返回对象,您可以通过getter 获取所有属性
"SELECT {"+ ArbRedirectHttpTypeModel.NEWURL +"}"
在这里,您试图返回模型的NEWURL
,我认为它将是一个字符串。灵活的搜索查询返回项目的pk,并默认将其转换为hybris模型。相反,尝试重新组织您的查询以选择pk
"SELECT {"+ ArbRedirectHttpTypeModel.PK +"}"
或者,您可以保持查询的原样,并使用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;