Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Error when Fetching data using Hibernate's ResultTransformer and SmartGWT

$
0
0
Be sure your post includes:

I am using version v10.0p_2015-01-23/PowerEdition Deployment (built 2015-01-23) and testing on FF 26. I am trying to get some data from the mssql 2008 database. For some reason I get this error.can somebody please help me to get it right.

Code:


[ERROR] [kaierpweb] - 11:46:38.630:XRP3:WARN:RPCManager:IllegalArgumentException occurred while calling setter of com.kaizen.erp.shared.entities.custom.CusNeighbourGroupInfo.rowNumundefined - response: {operationId: "CusNeiGroupDS_fetch",
clientContext: Obj,
internalClientContext: Obj,
context: Obj,
transactionNum: 1,
httpResponseCode: 200,
httpResponseText: "//isc_RPCResponseStart-->[{affectedRows:..."[260],
xmlHttpRequest: [object XMLHttpRequest],
transport: "xmlHttpRequest",
status: -1,
clientOnly: undef,
httpHeaders: Obj,
isStructured: true,
callbackArgs: null,
results: Obj,
affectedRows: 0,
data: "IllegalArgumentException occurred while ..."[124],
invalidateCache: false,
isDSResponse: true,
queueStatus: -1,
startRow: 0,
endRow: 0,
totalRows: 0}

This is my fetch method. I am using hibernate's ResultTransformer to get the required data from the query and passing it to the DSResponse to show on the client side. I am using the rowNum to limit fetch on the client side.

Code:

@SuppressWarnings("unchecked")
    public DSResponse fetch(DSRequest dsRequest) throws Exception
    {
        logger.info("> fetch");
        Session hibernateSession = HibernateUtills.getInstance().getHibernateSession();

        DebugTools.printj("-----------------------  FETCH  -----------------------");
       
        Map<String, Object> filtercriteria = dsRequest.getCriteria();
       
        DebugTools.printj("-----------------------  filtercriteria  -----------------------"+filtercriteria);
       
        String selectQuery =  "dbo.province.provincename AS province, dbo.province.capital, dbo.province.code, "
                + "dbo.province.telcode, dbo.county.countyname  AS county, dbo.district.districtname  AS district, "
                + "dbo.zone.alternateName  AS zone, dbo.neighbourhood.alternateName AS neighbour, dbo.city.cityname  AS city, "
                + "dbo.city.taxcode as taxcodecity, dbo.city.fdocode, COUNT(dbo.customer.customeraltname) AS countCustomer "
                + "FROM dbo.county "
                + "LEFT OUTER JOIN dbo.province ON (dbo.county.provinceID = dbo.province.id) "
                + "LEFT OUTER JOIN dbo.district ON (dbo.county.id = dbo.district.countyID) LEFT OUTER JOIN dbo.city ON (dbo.district.id = dbo.city.districtID) "
                + "LEFT OUTER JOIN dbo.zone ON (dbo.city.id = dbo.zone.cityId) LEFT OUTER JOIN dbo.neighbourhood ON (dbo.zone.id = dbo.neighbourhood.zoneId) "
                + "LEFT OUTER JOIN dbo.customer ON (dbo.neighbourhood.id = dbo.customer.neighbourhoodId) ";
             
       
        String countQuery = "SELECT count(dbo.county.id) "
                + "FROM dbo.county "
                + "LEFT OUTER JOIN dbo.province ON (dbo.county.provinceID = dbo.province.id) "
                + "LEFT OUTER JOIN dbo.district ON (dbo.county.id = dbo.district.countyID) LEFT OUTER JOIN dbo.city ON (dbo.district.id = dbo.city.districtID) "
                + "LEFT OUTER JOIN dbo.zone ON (dbo.city.id = dbo.zone.cityId) LEFT OUTER JOIN dbo.neighbourhood ON (dbo.zone.id = dbo.neighbourhood.zoneId) "
                + "LEFT OUTER JOIN dbo.customer ON (dbo.neighbourhood.id = dbo.customer.neighbourhoodId) ";               
       
        if (filtercriteria != null)
        {
            for (String key : filtercriteria.keySet())
            {
                if(!selectQuery.trim().contains("where")){
                    selectQuery+=" where ";
                    countQuery+=" where ";
                }
                else{
                    selectQuery+=" and ";
                    countQuery+=" and ";
                }
               
                if (key.equalsIgnoreCase("province")) {
                    selectQuery += "dbo.province.provincename like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.province.provincename like '%"+filtercriteria.get(key).toString()+"%'";
                }
                else if (key.equalsIgnoreCase("capital")) {
                    selectQuery += "dbo.province.capital like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.province.capital like '%"+filtercriteria.get(key).toString()+"%'";
                } else if (key.equalsIgnoreCase("code")) {
                    selectQuery += "dbo.province.code like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.province.code like '%"+filtercriteria.get(key).toString()+"%'";
                } else if (key.equalsIgnoreCase("county")) {
                    selectQuery += "dbo.county.countyname like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.county.countyname like '%"+filtercriteria.get(key).toString()+"%'";
                } else if (key.equalsIgnoreCase("district")) {
                    selectQuery += "dbo.district.districtname like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.district.districtname like '%"+filtercriteria.get(key).toString()+"%'";
                } else if (key.equalsIgnoreCase("city")) {
                    selectQuery += "dbo.city.cityname like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.city.cityname like '%"+filtercriteria.get(key).toString()+"%'";
                } else if (key.equalsIgnoreCase("zone")) {
                    selectQuery += "dbo.zone.alternateName like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.zone.alternateName like '%"+filtercriteria.get(key).toString()+"%'";
                } else if (key.equalsIgnoreCase("neighbour")) {
                    selectQuery += "dbo.neighbourhood.alternateName like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.neighbourhood.alternateName like '%"+filtercriteria.get(key).toString()+"%'";
                }
                else if (key.equalsIgnoreCase("telcode")) {
                    selectQuery += "dbo.province.telcode like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.province.telcode like '%"+filtercriteria.get(key).toString()+"%'";
                }
                else if (key.equalsIgnoreCase("fdocode")) {
                    selectQuery += "dbo.city.fdocode like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.city.fdocode like '%"+filtercriteria.get(key).toString()+"%'";
                }
                else if (key.equalsIgnoreCase("taxcodecity")) {
                    selectQuery += "dbo.city.taxcode like '%"+filtercriteria.get(key).toString()+"%'";
                    countQuery += "dbo.city.taxcode like '%"+filtercriteria.get(key).toString()+"%'";
                }
            }
        }
       
        selectQuery += "GROUP BY dbo.province.provincename, dbo.province.capital, dbo.province.code, "
                + "dbo.province.telcode, dbo.county.countyname, dbo.district.districtname, dbo.zone.alternateName, "
                + "dbo.neighbourhood.alternateName, dbo.city.cityname, dbo.city.taxcode, dbo.city.fdocode, dbo.county.id";
       
        System.out.println("selectQuery = "+selectQuery);
        Query countquery = hibernateSession.createSQLQuery(countQuery);

    // this implementation shows data paging (returning only ranges of requested records)
        Long startRow = dsRequest.getStartRow();
        Long endRow = dsRequest.getEndRow();
       
        Integer totalRows = (Integer) countquery.uniqueResult();
       
        DebugTools.printj(" TOTAL ROWS  "+totalRows);
       
        if (startRow != null && endRow != null) {
            selectQuery = "SELECT * FROM (SELECT ROW_NUMBER() OVER ( ORDER BY dbo.county.id) AS rowNum," +
                    selectQuery + ") as result WHERE rowNum >= " + startRow + " AND rowNum <= " + endRow +
                    " ORDER BY rowNum";
        }
        else
            selectQuery = "SELECT "+selectQuery;
       
        DebugTools.printj(" TOTAL ROWS  selectQuery  "+selectQuery);
       
        Query query = hibernateSession.createSQLQuery(selectQuery);
        query.setResultTransformer(Transformers.aliasToBean(CusNeighbourGroupInfo.class));
        List<CusNeighbourGroupInfo> list = query.list();
       
        DSResponse dsResponse = new DSResponse();
        dsResponse.setTotalRows(totalRows);
        dsResponse.setStartRow(startRow);

        endRow = Math.min(endRow, totalRows);
        dsResponse.setEndRow(endRow);
        // just return the List of matching beans
        dsResponse.setData(list);
         
        //dsResponse.setData(order);
        HibernateUtills.getInstance().closeSession();
        logger.info("< fetch");
        return dsResponse;
    }


Viewing all articles
Browse latest Browse all 4756

Latest Images

Trending Articles



Latest Images