简体   繁体   中英

Exception in java using dao class to get row

My DAO Class:

@SuppressWarnings("unchecked")
public int getRowCount(Map<String, Object> searchParam) throws DAOReadException {
    List<Client> clientRow = null;
    try {
        Criteria criteria = Criteria.forClass(Client.class);
        //set criteria search
        for (String key : searchParam.keySet()) {

            /*if(key.equals("ClientPK.clientId1")){
                criteria.add(Restrictions.like("ClientPK.clientId", searchParam.get(key)));
            }*/
            if(key.equals("clientPK.clientId")){
                criteria.add(Restrictions.eq(key, Integer.parseInt(searchParam.get(key).toString())));
            }
            if(key.equals("clientName")){
                criteria.add(Restrictions.like(key, searchParam.get(key)));
            }

            if(key.equals("status")){
                criteria.add(Restrictions.eq(key, Short.parseShort(searchParam.get(key).toString())));
            }


            //Bug# 12544 start
            if(key.equals("orgId"))
            {
                criteria.add(Restrictions.eq("ClientPK.orgId", searchParam.get(key)));
            }
            //Bug# 12544 End
    }
        criteria.addOrder(Order.desc("createdDate"));
        clientRow = (List<Client>) findByCriteria(criteria);
    }

    catch (Exception e) {
        throw new DAOReadException(e);
    }
    int rowCount = 0;
    if (clientRow != null) {
        rowCount = clientRow.size();
    }

    return rowCount;
}

}

error is :

java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: ClientPK of: com.vin.eretail.model.client.Client [select this from com.vin.eretail.model.client.Client as this where this.ClientPK.orgId=? order by this.createdDate desc]

seems to change like below:

    //Bug# 12544 start
    if(key.equals("orgId"))
    {
       criteria.add(Restrictions.eq("clientPK.orgId", searchParam.get(key)));
     }
        //Bug# 12544 End

still need to see your Client class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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