0
  public List<Client> findClientByAssociateUser(String userId) {
        logger.info("Enter find list of clients by this user");
        org.hibernate.Query query = sessionFactory.getCurrentSession()
                .createQuery("SELECT c.id, c.clientName, c.billingAddress,c.contactNumber"
                + " from Client c, User ud"
                + " WHERE ud.id = c.userId and ud.id = :id")
                .setString("id", userId);
        List<Client> result = (List<Client>) query.list();
        logger.info("Exit find list of clients");
        return result;
    }

public ModelAndView userDetails(@PathVariable String id, HttpServletRequest request) {
    ModelAndView mvc = new ModelAndView();        
    List<Client> clientList = userRepository.findClientByAssociateUser(id.toString());
       mvc.addObject("clientList", clientList);
       for (Client client : clientList) {
        System.out.println("Client Name{" + client.getClientName());
    }
    mvc.setViewName(MANAGEUSER_PREFIX + "details");
    return mvc;
}

我正进入(状态:

Ljava.lang.Object; cannot be cast to Client
4

1 回答 1

0

查询中的返回类型将是List<Object[] >.

因为你的查询说

SELECT c.id, c.clientName, c.billingAddress,c.c......

改变

List<Client> result = (List<Client>) query.list();

然后按照那个处理

List<Object[]> result = (List<Object[]>) query.list();

或将查询更改为

   SELECT c from Client c......
于 2013-03-20T17:04:44.757 回答