Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从列表到整型。无法转换查询结果_Java_Mysql_Arraylist_Hybris - Fatal编程技术网

Java 从列表到整型。无法转换查询结果

Java 从列表到整型。无法转换查询结果,java,mysql,arraylist,hybris,Java,Mysql,Arraylist,Hybris,我有一个疑问: select count(*) from {Order as or join CustomerOrderStatus as os on {or:CustomerOrderStatus}={os:pk} join OrderEntry as oe on {or.pk}={oe.order} join PurchaseAmount as pa on {or.pointOfSale}={pa.purchaseAmountOwner} join PurchaseAmountTimeSli

我有一个疑问:

select count(*) from {Order as or join CustomerOrderStatus as os on
{or:CustomerOrderStatus}={os:pk} join OrderEntry as oe on
{or.pk}={oe.order} join PurchaseAmount as pa on
{or.pointOfSale}={pa.purchaseAmountOwner} join PurchaseAmountTimeSlice
as ts on {pa.pk}={ts.purchaseamount}} where {or:company} in
(8796093710341) and {or:pointOfSale} in (8796097413125)
我用Java编写了以下代码来检索结果:

FlexibleSearchQuery query = new FlexibleSearchQuery(queryBuilder.toString());
List<Integer> result = new ArrayList<Integer>();
result = getFlexibleSearchService().<Integer> search(query).getResult();

如何获取int值?

count(*)
替换为
count({or:Pk})
,并将灵活搜索查询的结果类设置为
Integer
,如下所示
query.setResultClassList(Collections.singletonList(Integer.class))

我是这样解决的:

private FlexibleSearchService flexibleSearchService;

    @Override
    public void onValidate(PurchaseAmountTimeSliceModel paramMODEL, InterceptorContext paramInterceptorContext)
        throws InterceptorException {

       //.....
       final StringBuilder queryBuilder = new StringBuilder();
        queryBuilder.append("select {ts.pk}");
        queryBuilder.append(
                " from {Order as or join CustomerOrderStatus as os on {or:CustomerOrderStatus}={os:pk} join OrderEntry as oe on {or.pk}={oe.order} ");
        queryBuilder.append(
                "join PurchaseAmount as pa on {or.pointOfSale}={pa.purchaseAmountOwner} join PurchaseAmountTimeSlice as ts on {pa.pk}={ts.purchaseamount}} where ");

        if (pointOfSale != null && company != null) {
            queryBuilder.append("{or:company} in (" + company.getPk() + ") and {or:pointOfSale} in ("
                    + pointOfSale.getPk() + ")");
        }
        FlexibleSearchQuery query = new FlexibleSearchQuery(queryBuilder.toString());
        SearchResult<PurchaseAmountTimeSliceModel> result = flexibleSearchService.search(query);

        if (result != null) {
            if (result.getCount() >= 10) {
                LOG.error("There's already 10 purchase amount time slices configured. You reached the limit.");
                throw new InterceptorException(
                        "There's already 10 purchase amount time slices configured. You reached the limit.");
            }
        }
    //.....
private FlexibleSearchService FlexibleSearchService;
@凌驾
public void onValidate(PurchaseAmountTimeSliceModel paramMODEL、InterceptorContext paramInterceptorContext)
抛出截取异常{
//.....
最终StringBuilder queryBuilder=新StringBuilder();
append(“选择{ts.pk}”);
queryBuilder.append(
“从{Order as或在{or:CustomerOrderStatus}={os:pk}上加入CustomerOrderStatus作为os或{or.pk}={oe.Order}上加入OrderEntry作为oe”);
queryBuilder.append(
“在{or.pointOfSale}={pa.purchaseAmountOwner}上将PurchaseAmountTimeSlice作为pa连接在{pa.pk}={ts.PurchaseAmount}}其中“;
if(销售点!=null&&company!=null){
追加(“+company.getPk()+”)中的({or:company})和(“+company.getPk()+”)中的{or:pointOfSale}”
+getPk()+”);
}
FlexibleSearchQuery=新建FlexibleSearchQuery(queryBuilder.toString());
SearchResult=flexibleSearchService.search(查询);
如果(结果!=null){
如果(result.getCount()>=10){
LOG.error(“已经配置了10个购买金额时间片。您已达到限制。”);
抛出新的拦截器异常(
“已配置10个购买金额时间片。您已达到限制。”);
}
}
//.....

解决方案类似;)

当您询问异常时,请始终发布异常的堆栈跟踪。您还可以非常清楚地证明您完全缺乏知识和经验。这就是我所说的“恐怖秀代码”。请使用更多“+company.getPk()+”所以,一旦你做了一个更糟糕的例子,我可以用SQL注入攻击你的网站。
private FlexibleSearchService flexibleSearchService;

    @Override
    public void onValidate(PurchaseAmountTimeSliceModel paramMODEL, InterceptorContext paramInterceptorContext)
        throws InterceptorException {

       //.....
       final StringBuilder queryBuilder = new StringBuilder();
        queryBuilder.append("select {ts.pk}");
        queryBuilder.append(
                " from {Order as or join CustomerOrderStatus as os on {or:CustomerOrderStatus}={os:pk} join OrderEntry as oe on {or.pk}={oe.order} ");
        queryBuilder.append(
                "join PurchaseAmount as pa on {or.pointOfSale}={pa.purchaseAmountOwner} join PurchaseAmountTimeSlice as ts on {pa.pk}={ts.purchaseamount}} where ");

        if (pointOfSale != null && company != null) {
            queryBuilder.append("{or:company} in (" + company.getPk() + ") and {or:pointOfSale} in ("
                    + pointOfSale.getPk() + ")");
        }
        FlexibleSearchQuery query = new FlexibleSearchQuery(queryBuilder.toString());
        SearchResult<PurchaseAmountTimeSliceModel> result = flexibleSearchService.search(query);

        if (result != null) {
            if (result.getCount() >= 10) {
                LOG.error("There's already 10 purchase amount time slices configured. You reached the limit.");
                throw new InterceptorException(
                        "There's already 10 purchase amount time slices configured. You reached the limit.");
            }
        }
    //.....